Adds unit tests for DynamicNode and DynamicPublishedContent, fixes both when querying for recursive properties.
Fixes: #U4-1839
This commit is contained in:
@@ -43,6 +43,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
|
||||
<umbracoNaviHide>1</umbracoNaviHide>
|
||||
<siteTitle><![CDATA[This is my site]]></siteTitle>
|
||||
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc="""">
|
||||
<content><![CDATA[<div>This is some content</div>]]></content>
|
||||
<umbracoUrlAlias><![CDATA[page2/alias, 2ndpagealias]]></umbracoUrlAlias>
|
||||
@@ -78,6 +79,38 @@ namespace Umbraco.Tests.PublishedContent
|
||||
/// <returns></returns>
|
||||
protected abstract dynamic GetDynamicNode(int id);
|
||||
|
||||
[Test]
|
||||
public void Recursive_Property()
|
||||
{
|
||||
var doc = GetDynamicNode(1174);
|
||||
var prop = doc.GetProperty("siteTitle", true);
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("This is my site", prop.Value);
|
||||
prop = doc.GetProperty("_siteTitle"); //test with underscore prefix
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("This is my site", prop.Value);
|
||||
Assert.AreEqual("This is my site", doc._siteTitle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the internal instance level caching of returning properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://issues.umbraco.org/issue/U4-1824
|
||||
/// http://issues.umbraco.org/issue/U4-1825
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void Can_Return_Property_And_Value()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
Assert.IsTrue(doc.HasProperty("umbracoUrlAlias"));
|
||||
var prop = doc.GetProperty("umbracoUrlAlias");
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("page2/alias, 2ndpagealias", prop.Value);
|
||||
Assert.AreEqual("page2/alias, 2ndpagealias", doc.umbracoUrlAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the IsLast method with the result set from a Where statement
|
||||
/// </summary>
|
||||
|
||||
@@ -637,7 +637,14 @@ namespace Umbraco.Web.Models
|
||||
|
||||
public IPublishedContentProperty GetProperty(string alias)
|
||||
{
|
||||
return GetProperty(alias, false);
|
||||
var prop = GetProperty(alias, false);
|
||||
if (prop == null && alias.StartsWith("_"))
|
||||
{
|
||||
//if it is prefixed and the first result failed, try to get it by recursive
|
||||
var recursiveAlias = alias.Substring(1, alias.Length - 1);
|
||||
return GetProperty(recursiveAlias, true);
|
||||
}
|
||||
return prop;
|
||||
}
|
||||
public IPublishedContentProperty GetProperty(string alias, bool recursive)
|
||||
{
|
||||
|
||||
@@ -1363,6 +1363,12 @@ namespace umbraco.MacroEngines
|
||||
prop = n.GetProperty(alias);
|
||||
}
|
||||
}
|
||||
if (prop == null && alias.StartsWith("_"))
|
||||
{
|
||||
//if the prop is still null but it starts with an _ then we'll check recursively
|
||||
var recursiveAlias = alias.Substring(1, alias.Length - 1);
|
||||
prop = n.GetProperty(recursiveAlias, true);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user