From a765f36d24952b389b685ea53392ba08bf5122a0 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 5 Mar 2013 21:00:16 +0600 Subject: [PATCH 1/2] Adds unit tests for DynamicNode and DynamicPublishedContent, fixes both when querying for recursive properties. Fixes: #U4-1839 --- .../DynamicDocumentTestsBase.cs | 33 +++++++++++++++++++ .../Models/DynamicPublishedContent.cs | 9 ++++- .../RazorDynamicNode/DynamicNode.cs | 6 ++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs index 86a47aea86..792b0eb444 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs @@ -43,6 +43,7 @@ namespace Umbraco.Tests.PublishedContent 1 + This is some content]]> @@ -78,6 +79,38 @@ namespace Umbraco.Tests.PublishedContent /// 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); + } + + /// + /// Tests the internal instance level caching of returning properties + /// + /// + /// http://issues.umbraco.org/issue/U4-1824 + /// http://issues.umbraco.org/issue/U4-1825 + /// + [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); + } + /// /// Tests the IsLast method with the result set from a Where statement /// diff --git a/src/Umbraco.Web/Models/DynamicPublishedContent.cs b/src/Umbraco.Web/Models/DynamicPublishedContent.cs index d1fc83d0df..53d56aac27 100644 --- a/src/Umbraco.Web/Models/DynamicPublishedContent.cs +++ b/src/Umbraco.Web/Models/DynamicPublishedContent.cs @@ -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) { diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs index 475d49d065..660c4b5a4c 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs @@ -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) { From a8936de638d37ae7534708be97dec150789d806a Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 5 Mar 2013 21:52:22 +0600 Subject: [PATCH 2/2] Fixes: #U4-1834 --- .../TestHelpers/BaseDatabaseFactoryTest.cs | 3 +++ .../umbraco/Search/ExamineEvents.cs | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 0158f90a60..f9637050c3 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -80,6 +80,9 @@ namespace Umbraco.Tests.TestHelpers new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true }; InitializeDatabase(); + + //ensure the configuration matches the current version for tests + SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3); } protected virtual void InitializeDatabase() diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs index fbbb1008ed..5eda0360c2 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs @@ -125,14 +125,9 @@ namespace umbraco.presentation.umbraco.Search private void IndexContent(IContent sender) { - //we do not need to index this item if it is published, this is because the item will get indexed - // by the UmbracoExamine.UmbracoEventManager when listening to content.AfterUpdateDocumentCache - - if (sender.Published) - return; - - //otherwise, we need to check for SupportUnpublishedContent because if we are indexing anything and it is - // not published the indexer will need to support unpublished items. + // Only add to indexes that have SupportUnpublishedContent set to true, this is because any indexer + // that only supports published content will be notified based on the UmbracoExamineManager.content_AfterUpdateDocumentCache + // event handler. ExamineManager.Instance.ReIndexNode( sender.ToXml(), "content",