Resolving dependencies & fixes published content tests

This commit is contained in:
Elitsa Marinovska
2021-01-26 11:19:09 +01:00
parent 01c03c19c3
commit 6536cf7ae4
8 changed files with 119 additions and 110 deletions

View File

@@ -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");
}

View File

@@ -223,18 +223,18 @@ namespace Umbraco.Tests.PublishedContent
var publishedContent = snapshot.Content.GetById(1);
Assert.IsNotNull(publishedContent);
Assert.AreEqual("val1", publishedContent.Value<string>("prop"));
Assert.AreEqual("val-fr1", publishedContent.Value<string>("prop", "fr-FR"));
Assert.AreEqual("val-uk1", publishedContent.Value<string>("prop", "en-UK"));
Assert.AreEqual("val1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop"));
Assert.AreEqual("val-fr1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "fr-FR"));
Assert.AreEqual("val-uk1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<string>("prop"));
Assert.AreEqual("val-fr2", draftContent.Value<string>("prop", "fr-FR"));
Assert.AreEqual("val-uk2", draftContent.Value<string>("prop", "en-UK"));
Assert.AreEqual("val2", draftContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop"));
Assert.AreEqual("val-fr2", draftContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "fr-FR"));
Assert.AreEqual("val-uk2", draftContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<string>("prop"));
Assert.AreEqual("val-fr1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<string>("prop"));
Assert.AreEqual("val-uk1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<string>("prop", culture: ""));
Assert.AreEqual("val1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<string>("prop"));
Assert.AreEqual("val1", againContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop"));
}
[Test]

View File

@@ -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<string, string>()
{
@@ -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<IVariationContextAccessor>(), Mock.Of<IContentTypeService>(), Mock.Of<IMediaTypeService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublishedUrlProvider>());
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<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
var dt = doc.ChildrenAsTable(ServiceContext, "Child");
var dt = doc.ChildrenAsTable(Mock.Of<IVariationContextAccessor>(), Mock.Of<IContentTypeService>(), Mock.Of<IMediaTypeService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublishedUrlProvider>(), "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<IVariationContextAccessor>(), Mock.Of<IContentTypeService>(), Mock.Of<IMediaTypeService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublishedUrlProvider>());
//will return an empty data table
Assert.AreEqual(0, dt.Columns.Count);
Assert.AreEqual(0, dt.Rows.Count);

View File

@@ -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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<NotSupportedException>(() => content.Value("welcomeText", "nl", fallback: Fallback.To(999)));
Assert.Throws<NotSupportedException>(() => content.Value(Factory.GetRequiredService<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop");
Assert.AreEqual("woop", value);
}
}

View File

@@ -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<int>("prop1") == 1234)
.Where(x => x.Value<int>(Mock.Of<IPublishedValueFallback>(), "prop1") == 1234)
.ToIndexedArray();
Assert.IsTrue(items.First().IsFirst());

View File

@@ -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<IPublishedValueFallback>())).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<IPublishedValueFallback>()))
.ToIndexedArray();
Assert.AreEqual(4, items.Length);
@@ -274,7 +274,7 @@ namespace Umbraco.Tests.PublishedContent
// explicitely returns a PublishedContentSet, not an IEnumerable<T>
.OfType<Home>() // ours, return IEnumerable<Home> (actually a PublishedContentSet<Home>)
.Where(x => x.IsVisible()) // so, here it's linq again :-(
.Where(x => x.IsVisible(Mock.Of<IPublishedValueFallback>())) // 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<IVariationContextAccessor>()))
{
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<IPublishedValueFallback>(), "testRecursive", fallback: Fallback.ToAncestors);
var nullVal = doc.Value(Factory.GetRequiredService<IPublishedValueFallback>(), "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<IPublishedValueFallback>(), "content");
Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal);
Assert.AreEqual("<div>This is some content</div>", propVal.ToString());
var propVal2 = doc.Value<IHtmlEncodedString>("content");
var propVal2 = doc.Value<IHtmlEncodedString>(Mock.Of<IPublishedValueFallback>(), "content");
Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal2);
Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());
var propVal3 = doc.Value("Content");
var propVal3 = doc.Value(Mock.Of<IPublishedValueFallback>(), "Content");
Assert.IsInstanceOf(typeof(IHtmlEncodedString), propVal3);
Assert.AreEqual("<div>This is some content</div>", propVal3.ToString());
}
@@ -402,8 +404,8 @@ namespace Umbraco.Tests.PublishedContent
var result = doc.Ancestors().OrderBy(x => x.Level)
.Single()
.Descendants()
.FirstOrDefault(x => x.Value<string>("selectedNodes", defaultValue: "").Split(',').Contains("1173"));
.Descendants(Mock.Of<IVariationContextAccessor>())
.FirstOrDefault(x => x.Value<string>(Mock.Of<IPublishedValueFallback>(), "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<IPublishedContent>());
Assert.IsNotNull(doc.FirstChild(Mock.Of<IVariationContextAccessor>()));
Assert.IsNotNull(doc.FirstChild(Mock.Of<IVariationContextAccessor>(), x => true));
Assert.IsNotNull(doc.FirstChild<IPublishedContent>(Mock.Of<IVariationContextAccessor>()));
doc = GetNode(1175); // does not have child nodes
Assert.IsNull(doc.FirstChild());
Assert.IsNull(doc.FirstChild(x => true));
Assert.IsNull(doc.FirstChild<IPublishedContent>());
Assert.IsNull(doc.FirstChild(Mock.Of<IVariationContextAccessor>()));
Assert.IsNull(doc.FirstChild(Mock.Of<IVariationContextAccessor>(), x => true));
Assert.IsNull(doc.FirstChild<IPublishedContent>(Mock.Of<IVariationContextAccessor>()));
}
[Test]
@@ -484,7 +486,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1046); // has child nodes
var model = doc.FirstChild<Home>(x => true); // predicate
var model = doc.FirstChild<Home>(Mock.Of<IVariationContextAccessor>(), x => true); // predicate
Assert.IsNotNull(model);
Assert.IsTrue(model.Id == 1173);
@@ -492,8 +494,8 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsInstanceOf<IPublishedContent>(model);
doc = GetNode(1175); // does not have child nodes
Assert.IsNull(doc.FirstChild<Anything>());
Assert.IsNull(doc.FirstChild<Anything>(x => true));
Assert.IsNull(doc.FirstChild<Anything>(Mock.Of<IVariationContextAccessor>()));
Assert.IsNull(doc.FirstChild<Anything>(Mock.Of<IVariationContextAccessor>(), 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<IPublishedValueFallback>(), Constants.Conventions.Content.UrlAlias);
var noValue = doc.HasValue(Mock.Of<IPublishedValueFallback>(), "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<IPublishedValueFallback>()));
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<IPublishedValueFallback>()));
Assert.IsTrue(visible.IsVisible(Mock.Of<IPublishedValueFallback>()));
}
[Test]
@@ -701,7 +703,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1046);
var result = doc.DescendantsOrSelf().ToArray();
var result = doc.DescendantsOrSelf(Mock.Of<IVariationContextAccessor>()).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<IVariationContextAccessor>()).ToArray();
Assert.IsNotNull(result);
@@ -845,17 +847,20 @@ namespace Umbraco.Tests.PublishedContent
_publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot(It.IsAny<string>())).Returns(new []{root});
CollectionAssertAreEqual(new []{root}, root.SiblingsAndSelf());
var variationContextAccessor = Factory.GetRequiredService<IVariationContextAccessor>();
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<string>())).Returns(new []{root});
CollectionAssertAreEqual(new IPublishedContent[0], root.Siblings());
var variationContextAccessor = Factory.GetRequiredService<IVariationContextAccessor>();
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<string>("legend");
public string Legend => this.Value<string>(Mock.Of<IPublishedValueFallback>(), "legend");
public IPublishedContent Image => this.Value<IPublishedContent>("image");
public IPublishedContent Image => this.Value<IPublishedContent>(Mock.Of<IPublishedValueFallback>(), "image");
public int Size => this.Value<int>("size");
public int Size => this.Value<int>(Mock.Of<IPublishedValueFallback>(), "size");
}
}
}

View File

@@ -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<IPublishedValueFallback>(), "content");
Assert.IsInstanceOf<IHtmlEncodedString>(propVal);
Assert.AreEqual("<div>This is some content</div>", propVal.ToString());
var propVal2 = publishedMedia.Value<IHtmlEncodedString>("content");
var propVal2 = publishedMedia.Value<IHtmlEncodedString>(Factory.GetRequiredService<IPublishedValueFallback>(), "content");
Assert.IsInstanceOf<IHtmlEncodedString>(propVal2);
Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());
var propVal3 = publishedMedia.Value("Content");
var propVal3 = publishedMedia.Value(Factory.GetRequiredService<IPublishedValueFallback>(), "Content");
Assert.IsInstanceOf<IHtmlEncodedString>(propVal3);
Assert.AreEqual("<div>This is some content</div>", 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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
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<IVariationContextAccessor>());
Assert.IsTrue(subDescendantsOrSelf.Select(x => x.Id).ContainsAll(
new[] { mChild1.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
}

View File

@@ -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> _membershipHelper;
private readonly IPublicAccessService _publicAccessService;
private readonly IContentService _contentService;
private readonly IPublishedValueFallback _publishedValueFallback;
public PublicAccessChecker(Lazy<MembershipHelper> membershipHelper, IPublicAccessService publicAccessService, IContentService contentService)
public PublicAccessChecker(Lazy<MembershipHelper> 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<bool>(Constants.Conventions.Member.IsApproved))
member.Value<bool>(_publishedValueFallback, Constants.Conventions.Member.IsApproved))
{
return PublicAccessStatus.LockedOut;
}