diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index cc3325377e..bd5c467c88 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -13,24 +13,20 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Core.Strings; -using Umbraco.Net; using Umbraco.Tests.Common; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing.Objects; -using Umbraco.Web; using Umbraco.Web.Cache; using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.NuCache; using Umbraco.Web.PublishedCache.NuCache.DataSource; -using Umbraco.Infrastructure.PublishedCache.Persistence; namespace Umbraco.Tests.PublishedContent { @@ -908,10 +904,10 @@ namespace Umbraco.Tests.PublishedContent documents = snapshot.Content.GetAtRoot("*").ToArray(); AssertDocuments(documents, "N1-fr-FR", null, "N3-fr-FR"); - documents = snapshot.Content.GetById(1).DescendantsOrSelf().ToArray(); + documents = snapshot.Content.GetById(1).DescendantsOrSelf(_variationAccesor).ToArray(); AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", "N12-fr-FR", "N6-fr-FR"); - documents = snapshot.Content.GetById(1).DescendantsOrSelf("*").ToArray(); + documents = snapshot.Content.GetById(1).DescendantsOrSelf(_variationAccesor, "*").ToArray(); AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", null /*11*/, "N12-fr-FR", null /*5*/, "N6-fr-FR"); } diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index b56c0047ed..f4803951f3 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -223,18 +223,18 @@ namespace Umbraco.Tests.PublishedContent var publishedContent = snapshot.Content.GetById(1); Assert.IsNotNull(publishedContent); - Assert.AreEqual("val1", publishedContent.Value("prop")); - Assert.AreEqual("val-fr1", publishedContent.Value("prop", "fr-FR")); - Assert.AreEqual("val-uk1", publishedContent.Value("prop", "en-UK")); + Assert.AreEqual("val1", publishedContent.Value(Mock.Of(), "prop")); + Assert.AreEqual("val-fr1", publishedContent.Value(Mock.Of(), "prop", "fr-FR")); + Assert.AreEqual("val-uk1", publishedContent.Value(Mock.Of(), "prop", "en-UK")); Assert.IsNull(publishedContent.Name(_variationAccesor)); // no invariant name for varying content Assert.AreEqual("name-fr1", publishedContent.Name(_variationAccesor, "fr-FR")); Assert.AreEqual("name-uk1", publishedContent.Name(_variationAccesor, "en-UK")); var draftContent = snapshot.Content.GetById(true, 1); - Assert.AreEqual("val2", draftContent.Value("prop")); - Assert.AreEqual("val-fr2", draftContent.Value("prop", "fr-FR")); - Assert.AreEqual("val-uk2", draftContent.Value("prop", "en-UK")); + Assert.AreEqual("val2", draftContent.Value(Mock.Of(), "prop")); + Assert.AreEqual("val-fr2", draftContent.Value(Mock.Of(), "prop", "fr-FR")); + Assert.AreEqual("val-uk2", draftContent.Value(Mock.Of(), "prop", "en-UK")); Assert.IsNull(draftContent.Name(_variationAccesor)); // no invariant name for varying content Assert.AreEqual("name-fr2", draftContent.Name(_variationAccesor, "fr-FR")); @@ -242,18 +242,18 @@ namespace Umbraco.Tests.PublishedContent // now french is default _variationAccesor.VariationContext = new VariationContext("fr-FR"); - Assert.AreEqual("val-fr1", publishedContent.Value("prop")); + Assert.AreEqual("val-fr1", publishedContent.Value(Mock.Of(), "prop")); Assert.AreEqual("name-fr1", publishedContent.Name(_variationAccesor)); Assert.AreEqual(new DateTime(2018, 01, 01, 01, 00, 00), publishedContent.CultureDate(_variationAccesor)); // now uk is default _variationAccesor.VariationContext = new VariationContext("en-UK"); - Assert.AreEqual("val-uk1", publishedContent.Value("prop")); + Assert.AreEqual("val-uk1", publishedContent.Value(Mock.Of(), "prop")); Assert.AreEqual("name-uk1", publishedContent.Name(_variationAccesor)); Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.CultureDate(_variationAccesor)); // invariant needs to be retrieved explicitly, when it's not default - Assert.AreEqual("val1", publishedContent.Value("prop", culture: "")); + Assert.AreEqual("val1", publishedContent.Value(Mock.Of(), "prop", culture: "")); // but, // if the content type / property type does not vary, then it's all invariant again @@ -271,7 +271,7 @@ namespace Umbraco.Tests.PublishedContent // now, "no culture" means "invariant" Assert.AreEqual("It Works1!", againContent.Name(_variationAccesor)); - Assert.AreEqual("val1", againContent.Value("prop")); + Assert.AreEqual("val1", againContent.Value(Mock.Of(), "prop")); } [Test] diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs index 7cc5bae403..1676ed9a20 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs @@ -1,10 +1,11 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Microsoft.Extensions.Logging.Abstractions; using Moq; using NUnit.Framework; +using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; @@ -12,7 +13,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers; -using Umbraco.Web; +using Umbraco.Web.Routing; namespace Umbraco.Tests.PublishedContent { @@ -27,7 +28,7 @@ namespace Umbraco.Tests.PublishedContent base.SetUp(); // need to specify a different callback for testing - PublishedContentExtensions.GetPropertyAliasesAndNames = (services, alias) => + PublishedContentExtensions.GetPropertyAliasesAndNames = (contentTypeService, mediaTypeService, memberTypeService, alias) => { var userFields = new Dictionary() { @@ -70,14 +71,14 @@ namespace Umbraco.Tests.PublishedContent public override void TearDown() { base.TearDown(); - Umbraco.Web.PublishedContentExtensions.GetPropertyAliasesAndNames = null; + PublishedContentExtensions.GetPropertyAliasesAndNames = null; } [Test] public void To_DataTable() { var doc = GetContent(true, 1); - var dt = doc.ChildrenAsTable(ServiceContext); + var dt = doc.ChildrenAsTable(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); Assert.AreEqual(11, dt.Columns.Count); Assert.AreEqual(3, dt.Rows.Count); @@ -100,7 +101,7 @@ namespace Umbraco.Tests.PublishedContent var c = (SolidPublishedContent)doc.Children.ElementAt(0); c.ContentType = new PublishedContentType(Guid.NewGuid(), 22, "DontMatch", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing); - var dt = doc.ChildrenAsTable(ServiceContext, "Child"); + var dt = doc.ChildrenAsTable(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), "Child"); Assert.AreEqual(11, dt.Columns.Count); Assert.AreEqual(2, dt.Rows.Count); @@ -116,7 +117,7 @@ namespace Umbraco.Tests.PublishedContent public void To_DataTable_No_Rows() { var doc = GetContent(false, 1); - var dt = doc.ChildrenAsTable(ServiceContext); + var dt = doc.ChildrenAsTable(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); //will return an empty data table Assert.AreEqual(0, dt.Columns.Count); Assert.AreEqual(0, dt.Rows.Count); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs index 7392537e39..7993ca025a 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -194,7 +195,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_For_Populated_Requested_Language() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "en-US"); + var value = content.Value(Mock.Of(), "welcomeText", "en-US"); Assert.AreEqual("Welcome", value); } @@ -202,7 +203,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_For_Populated_Requested_Non_Default_Language() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "de"); + var value = content.Value(Mock.Of(), "welcomeText", "de"); Assert.AreEqual("Willkommen", value); } @@ -210,7 +211,7 @@ namespace Umbraco.Tests.PublishedContent public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_Without_Fallback() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "fr"); + var value = content.Value(Mock.Of(), "welcomeText", "fr"); Assert.IsNull(value); } @@ -218,7 +219,7 @@ namespace Umbraco.Tests.PublishedContent public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Unless_Requested() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "es"); + var value = content.Value(Mock.Of(), "welcomeText", "es"); Assert.IsNull(value); } @@ -226,7 +227,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "es", fallback: Fallback.ToLanguage); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "es", fallback: Fallback.ToLanguage); Assert.AreEqual("Welcome", value); } @@ -234,7 +235,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Over_Two_Levels() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "it", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors)); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "it", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors)); Assert.AreEqual("Welcome", value); } @@ -242,7 +243,7 @@ namespace Umbraco.Tests.PublishedContent public void Do_Not_GetContent_For_Unpopulated_Requested_Language_With_Fallback_Over_That_Loops() { var content = Current.UmbracoContext.Content.GetAtRoot().First(); - var value = content.Value("welcomeText", "no", fallback: Fallback.ToLanguage); + var value = content.Value(Mock.Of(), "welcomeText", "no", fallback: Fallback.ToLanguage); Assert.IsNull(value); } @@ -250,7 +251,7 @@ namespace Umbraco.Tests.PublishedContent public void Do_Not_Get_Content_Recursively_Unless_Requested() { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); - var value = content.Value("welcomeText2"); + var value = content.Value(Mock.Of(), "welcomeText2"); Assert.IsNull(value); } @@ -258,7 +259,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_Recursively() { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); - var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); + var value = content.Value(Factory.GetRequiredService(), "welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); } @@ -267,7 +268,7 @@ namespace Umbraco.Tests.PublishedContent { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First(); Assert.IsNull(content.GetProperty("welcomeText2")); - var value = content.Value("welcomeText2"); + var value = content.Value(Mock.Of(), "welcomeText2"); Assert.IsNull(value); } @@ -276,7 +277,7 @@ namespace Umbraco.Tests.PublishedContent { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First(); Assert.IsNull(content.GetProperty("welcomeText2")); - var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); + var value = content.Value(Factory.GetRequiredService(), "welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); } @@ -285,7 +286,7 @@ namespace Umbraco.Tests.PublishedContent { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First(); Assert.IsNull(content.GetProperty("noprop")); - var value = content.Value("noprop", fallback: Fallback.ToAncestors); + var value = content.Value(Factory.GetRequiredService(), "noprop", fallback: Fallback.ToAncestors); // property has no value but we still get the value (ie, the converter would do something) Assert.AreEqual("xxx", value); } @@ -296,7 +297,7 @@ namespace Umbraco.Tests.PublishedContent Current.VariationContextAccessor.VariationContext = new VariationContext("nl"); var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); - var value = content.Value("welcomeText", "nl", fallback: Fallback.To(Fallback.Ancestors, Fallback.Language)); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl", fallback: Fallback.To(Fallback.Ancestors, Fallback.Language)); // No Dutch value is directly assigned. Check has fallen back to Dutch value from parent. Assert.AreEqual("Welkom", value); @@ -306,7 +307,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_With_Fallback_Language_Priority() { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); - var value = content.Value("welcomeText", "nl", fallback: Fallback.ToLanguage); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl", fallback: Fallback.ToLanguage); // No Dutch value is directly assigned. Check has fallen back to English value from language variant. Assert.AreEqual("Welcome", value); @@ -316,7 +317,7 @@ namespace Umbraco.Tests.PublishedContent public void Throws_For_Non_Supported_Fallback() { var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); - Assert.Throws(() => content.Value("welcomeText", "nl", fallback: Fallback.To(999))); + Assert.Throws(() => content.Value(Factory.GetRequiredService(), "welcomeText", "nl", fallback: Fallback.To(999))); } [Test] @@ -325,15 +326,15 @@ namespace Umbraco.Tests.PublishedContent var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First(); // no Dutch value is assigned, so getting null - var value = content.Value("welcomeText", "nl"); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl"); Assert.IsNull(value); // even if we 'just' provide a default value - value = content.Value("welcomeText", "nl", defaultValue: "woop"); + value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl", defaultValue: "woop"); Assert.IsNull(value); // but it works with proper fallback settings - value = content.Value("welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop"); + value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop"); Assert.AreEqual("woop", value); } @@ -348,15 +349,15 @@ namespace Umbraco.Tests.PublishedContent prop.SetValue("nl", "nope"); // HasValue false but getting value returns this // there is an EN value - var value = content.Value("welcomeText", "en-US"); + var value = content.Value(Factory.GetRequiredService(), "welcomeText", "en-US"); Assert.AreEqual("Welcome", value); // there is no NL value and we get the 'converted' value - value = content.Value("welcomeText", "nl"); + value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl"); Assert.AreEqual("nope", value); // but it works with proper fallback settings - value = content.Value("welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop"); + value = content.Value(Factory.GetRequiredService(), "welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop"); Assert.AreEqual("woop", value); } } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index 88de95178e..1bfb147d26 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using NUnit.Framework; @@ -165,7 +165,7 @@ namespace Umbraco.Tests.PublishedContent public void Position() { var items = Current.UmbracoContext.Content.GetAtRoot() - .Where(x => x.Value("prop1") == 1234) + .Where(x => x.Value(Mock.Of(), "prop1") == 1234) .ToIndexedArray(); Assert.IsTrue(items.First().IsFirst()); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index af0dab8e14..a076deb8b3 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -191,7 +191,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var items = doc.Children(VariationContextAccessor).Where(x => x.IsVisible()).ToIndexedArray(); + var items = doc.Children(VariationContextAccessor).Where(x => x.IsVisible(Mock.Of())).ToIndexedArray(); foreach (var item in items) { @@ -213,7 +213,7 @@ namespace Umbraco.Tests.PublishedContent var items = doc .Children(VariationContextAccessor) - .Where(x => x.IsVisible()) + .Where(x => x.IsVisible(Mock.Of())) .ToIndexedArray(); Assert.AreEqual(4, items.Length); @@ -274,7 +274,7 @@ namespace Umbraco.Tests.PublishedContent // explicitely returns a PublishedContentSet, not an IEnumerable .OfType() // ours, return IEnumerable (actually a PublishedContentSet) - .Where(x => x.IsVisible()) // so, here it's linq again :-( + .Where(x => x.IsVisible(Mock.Of())) // so, here it's linq again :-( .ToIndexedArray(); // so, we need that one for the test to pass Assert.AreEqual(1, items.Length); @@ -363,16 +363,18 @@ namespace Umbraco.Tests.PublishedContent var exindex = 0; // must respect the XPath descendants-or-self axis! - foreach (var d in doc.DescendantsOrSelf()) + foreach (var d in doc.DescendantsOrSelf(Mock.Of())) + { Assert.AreEqual(expected[exindex++], d.Id); + } } [Test] public void Get_Property_Value_Recursive() { var doc = GetNode(1174); - var rVal = doc.Value("testRecursive", fallback: Fallback.ToAncestors); - var nullVal = doc.Value("DoNotFindThis", fallback: Fallback.ToAncestors); + var rVal = doc.Value(Factory.GetRequiredService(), "testRecursive", fallback: Fallback.ToAncestors); + var nullVal = doc.Value(Factory.GetRequiredService(), "DoNotFindThis", fallback: Fallback.ToAncestors); Assert.AreEqual("This is the recursive val", rVal); Assert.AreEqual(null, nullVal); } @@ -382,15 +384,15 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var propVal = doc.Value("content"); + var propVal = doc.Value(Mock.Of(), "content"); Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal); Assert.AreEqual("
This is some content
", propVal.ToString()); - var propVal2 = doc.Value("content"); + var propVal2 = doc.Value(Mock.Of(), "content"); Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal2); Assert.AreEqual("
This is some content
", propVal2.ToString()); - var propVal3 = doc.Value("Content"); + var propVal3 = doc.Value(Mock.Of(), "Content"); Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal3); Assert.AreEqual("
This is some content
", propVal3.ToString()); } @@ -402,8 +404,8 @@ namespace Umbraco.Tests.PublishedContent var result = doc.Ancestors().OrderBy(x => x.Level) .Single() - .Descendants() - .FirstOrDefault(x => x.Value("selectedNodes", defaultValue: "").Split(',').Contains("1173")); + .Descendants(Mock.Of()) + .FirstOrDefault(x => x.Value(Mock.Of(), "selectedNodes", defaultValue: "").Split(',').Contains("1173")); Assert.IsNotNull(result); } @@ -469,14 +471,14 @@ namespace Umbraco.Tests.PublishedContent public void FirstChild() { var doc = GetNode(1173); // has child nodes - Assert.IsNotNull(doc.FirstChild()); - Assert.IsNotNull(doc.FirstChild(x => true)); - Assert.IsNotNull(doc.FirstChild()); + Assert.IsNotNull(doc.FirstChild(Mock.Of())); + Assert.IsNotNull(doc.FirstChild(Mock.Of(), x => true)); + Assert.IsNotNull(doc.FirstChild(Mock.Of())); doc = GetNode(1175); // does not have child nodes - Assert.IsNull(doc.FirstChild()); - Assert.IsNull(doc.FirstChild(x => true)); - Assert.IsNull(doc.FirstChild()); + Assert.IsNull(doc.FirstChild(Mock.Of())); + Assert.IsNull(doc.FirstChild(Mock.Of(), x => true)); + Assert.IsNull(doc.FirstChild(Mock.Of())); } [Test] @@ -484,7 +486,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1046); // has child nodes - var model = doc.FirstChild(x => true); // predicate + var model = doc.FirstChild(Mock.Of(), x => true); // predicate Assert.IsNotNull(model); Assert.IsTrue(model.Id == 1173); @@ -492,8 +494,8 @@ namespace Umbraco.Tests.PublishedContent Assert.IsInstanceOf(model); doc = GetNode(1175); // does not have child nodes - Assert.IsNull(doc.FirstChild()); - Assert.IsNull(doc.FirstChild(x => true)); + Assert.IsNull(doc.FirstChild(Mock.Of())); + Assert.IsNull(doc.FirstChild(Mock.Of(), x => true)); } [Test] @@ -521,8 +523,8 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var hasValue = doc.HasValue(Constants.Conventions.Content.UrlAlias); - var noValue = doc.HasValue("blahblahblah"); + var hasValue = doc.HasValue(Mock.Of(), Constants.Conventions.Content.UrlAlias); + var noValue = doc.HasValue(Mock.Of(), "blahblahblah"); Assert.IsTrue(hasValue); Assert.IsFalse(noValue); @@ -533,7 +535,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1174); - var whereVisible = doc.Ancestors().Where(x => x.IsVisible()); + var whereVisible = doc.Ancestors().Where(x => x.IsVisible(Mock.Of())); Assert.AreEqual(1, whereVisible.Count()); } @@ -544,8 +546,8 @@ namespace Umbraco.Tests.PublishedContent var hidden = GetNode(1046); var visible = GetNode(1173); - Assert.IsFalse(hidden.IsVisible()); - Assert.IsTrue(visible.IsVisible()); + Assert.IsFalse(hidden.IsVisible(Mock.Of())); + Assert.IsTrue(visible.IsVisible(Mock.Of())); } [Test] @@ -701,7 +703,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1046); - var result = doc.DescendantsOrSelf().ToArray(); + var result = doc.DescendantsOrSelf(Mock.Of()).ToArray(); Assert.IsNotNull(result); @@ -714,7 +716,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1046); - var result = doc.Descendants().ToArray(); + var result = doc.Descendants(Mock.Of()).ToArray(); Assert.IsNotNull(result); @@ -845,17 +847,20 @@ namespace Umbraco.Tests.PublishedContent _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot(It.IsAny())).Returns(new []{root}); - CollectionAssertAreEqual(new []{root}, root.SiblingsAndSelf()); + var variationContextAccessor = Factory.GetRequiredService(); + var publishedSnapshot = _publishedSnapshotAccessorMock.Object.PublishedSnapshot; - CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_1.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_2.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_3.SiblingsAndSelf()); + CollectionAssertAreEqual(new []{root}, root.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_1.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_2.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_3.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_4.SiblingsAndSelf()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_5.SiblingsAndSelf()); + CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_1.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_2.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1, level1_2, level1_3}, level1_3.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_1.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_2.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_3.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_4.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_5.SiblingsAndSelf(publishedSnapshot, variationContextAccessor)); } @@ -884,17 +889,20 @@ namespace Umbraco.Tests.PublishedContent _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot(It.IsAny())).Returns(new []{root}); - CollectionAssertAreEqual(new IPublishedContent[0], root.Siblings()); + var variationContextAccessor = Factory.GetRequiredService(); + var publishedSnapshot = _publishedSnapshotAccessorMock.Object.PublishedSnapshot; - CollectionAssertAreEqual( new []{level1_2, level1_3}, level1_1.Siblings()); - CollectionAssertAreEqual( new []{level1_1, level1_3}, level1_2.Siblings()); - CollectionAssertAreEqual( new []{level1_1, level1_2}, level1_3.Siblings()); + CollectionAssertAreEqual(new IPublishedContent[0], root.Siblings(publishedSnapshot, variationContextAccessor)); - CollectionAssertAreEqual( new []{ level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_1.Siblings()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_3, level1_1_4, level1_1_5}, level1_1_2.Siblings()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_4, level1_1_5}, level1_1_3.Siblings()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_5}, level1_1_4.Siblings()); - CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4}, level1_1_5.Siblings()); + CollectionAssertAreEqual( new []{level1_2, level1_3}, level1_1.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1, level1_3}, level1_2.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1, level1_2}, level1_3.Siblings(publishedSnapshot, variationContextAccessor)); + + CollectionAssertAreEqual( new []{ level1_1_2, level1_1_3, level1_1_4, level1_1_5}, level1_1_1.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_3, level1_1_4, level1_1_5}, level1_1_2.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_4, level1_1_5}, level1_1_3.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_5}, level1_1_4.Siblings(publishedSnapshot, variationContextAccessor)); + CollectionAssertAreEqual( new []{level1_1_1, level1_1_2, level1_1_3, level1_1_4}, level1_1_5.Siblings(publishedSnapshot, variationContextAccessor)); } @@ -968,11 +976,11 @@ namespace Umbraco.Tests.PublishedContent { } - public string Legend => this.Value("legend"); + public string Legend => this.Value(Mock.Of(), "legend"); - public IPublishedContent Image => this.Value("image"); + public IPublishedContent Image => this.Value(Mock.Of(), "image"); - public int Size => this.Value("size"); + public int Size => this.Value(Mock.Of(), "size"); } } } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index 912d1e4995..ee69ecf4b2 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -1,4 +1,4 @@ -using System.Web; +using System.Web; using System.Xml.Linq; using System.Xml.XPath; using NUnit.Framework; @@ -103,15 +103,15 @@ namespace Umbraco.Tests.PublishedContent var publishedMedia = GetNode(media.Id); - var propVal = publishedMedia.Value("content"); + var propVal = publishedMedia.Value(Factory.GetRequiredService(), "content"); Assert.IsInstanceOf(propVal); Assert.AreEqual("
This is some content
", propVal.ToString()); - var propVal2 = publishedMedia.Value("content"); + var propVal2 = publishedMedia.Value(Factory.GetRequiredService(), "content"); Assert.IsInstanceOf(propVal2); Assert.AreEqual("
This is some content
", propVal2.ToString()); - var propVal3 = publishedMedia.Value("Content"); + var propVal3 = publishedMedia.Value(Factory.GetRequiredService(), "Content"); Assert.IsInstanceOf(propVal3); Assert.AreEqual("
This is some content
", propVal3.ToString()); } @@ -240,11 +240,11 @@ namespace Umbraco.Tests.PublishedContent //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); - var rootDescendants = publishedMedia.Descendants(); + var rootDescendants = publishedMedia.Descendants(Factory.GetRequiredService()); Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 2112, 2222, 1113, 1114, 1115, 1116 })); var publishedChild1 = cache.GetById(2222); - var subDescendants = publishedChild1.Descendants(); + var subDescendants = publishedChild1.Descendants(Factory.GetRequiredService()); Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2112, 3113 })); } } @@ -268,11 +268,11 @@ namespace Umbraco.Tests.PublishedContent //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); - var rootDescendants = publishedMedia.DescendantsOrSelf(); + var rootDescendants = publishedMedia.DescendantsOrSelf(Factory.GetRequiredService()); Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 })); var publishedChild1 = cache.GetById(2222); - var subDescendants = publishedChild1.DescendantsOrSelf(); + var subDescendants = publishedChild1.DescendantsOrSelf(Factory.GetRequiredService()); Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 })); } } @@ -368,11 +368,11 @@ namespace Umbraco.Tests.PublishedContent var mSubChild3 = MakeNewMedia("SubChild3", mType, user, mChild1.Id); var publishedMedia = GetNode(mRoot.Id); - var rootDescendants = publishedMedia.Descendants(); + var rootDescendants = publishedMedia.Descendants(Factory.GetRequiredService()); Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { mChild1.Id, mChild2.Id, mChild3.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id })); var publishedChild1 = GetNode(mChild1.Id); - var subDescendants = publishedChild1.Descendants(); + var subDescendants = publishedChild1.Descendants(Factory.GetRequiredService()); Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { mSubChild1.Id, mSubChild2.Id, mSubChild3.Id })); } @@ -392,12 +392,12 @@ namespace Umbraco.Tests.PublishedContent var mSubChild3 = MakeNewMedia("SubChild3", mType, user, mChild1.Id); var publishedMedia = GetNode(mRoot.Id); - var rootDescendantsOrSelf = publishedMedia.DescendantsOrSelf(); + var rootDescendantsOrSelf = publishedMedia.DescendantsOrSelf(Factory.GetRequiredService()); Assert.IsTrue(rootDescendantsOrSelf.Select(x => x.Id).ContainsAll( new[] { mRoot.Id, mChild1.Id, mChild2.Id, mChild3.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id })); var publishedChild1 = GetNode(mChild1.Id); - var subDescendantsOrSelf = publishedChild1.DescendantsOrSelf(); + var subDescendantsOrSelf = publishedChild1.DescendantsOrSelf(Factory.GetRequiredService()); Assert.IsTrue(subDescendantsOrSelf.Select(x => x.Id).ContainsAll( new[] { mChild1.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id })); } diff --git a/src/Umbraco.Web/Security/PublicAccessChecker.cs b/src/Umbraco.Web/Security/PublicAccessChecker.cs index 1ea22586e5..039557de42 100644 --- a/src/Umbraco.Web/Security/PublicAccessChecker.cs +++ b/src/Umbraco.Web/Security/PublicAccessChecker.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core; +using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; namespace Umbraco.Web.Security @@ -10,12 +11,14 @@ namespace Umbraco.Web.Security private readonly Lazy _membershipHelper; private readonly IPublicAccessService _publicAccessService; private readonly IContentService _contentService; + private readonly IPublishedValueFallback _publishedValueFallback; - public PublicAccessChecker(Lazy membershipHelper, IPublicAccessService publicAccessService, IContentService contentService) + public PublicAccessChecker(Lazy membershipHelper, IPublicAccessService publicAccessService, IContentService contentService, IPublishedValueFallback publishedValueFallback) { _membershipHelper = membershipHelper; _publicAccessService = publicAccessService; _contentService = contentService; + _publishedValueFallback = publishedValueFallback; } public PublicAccessStatus HasMemberAccessToContent(int publishedContentId) @@ -43,7 +46,7 @@ namespace Umbraco.Web.Security } if (member.HasProperty(Constants.Conventions.Member.IsLockedOut) && - member.Value(Constants.Conventions.Member.IsApproved)) + member.Value(_publishedValueFallback, Constants.Conventions.Member.IsApproved)) { return PublicAccessStatus.LockedOut; }