Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PublishedCache/PublishedContentLanguageVariantTests.cs

378 lines
16 KiB
C#
Raw Normal View History

V15: Remove Nucache (#17166) * Remove nucache reference from Web.Common * Get tests building-ish * Move ReservedFieldNamesService to the right project * Remove IPublishedSnapshotStatus * Added functionality to the INavigationQueryService to get root keys * Fixed issue with navigation * Remove IPublishedSnapshot from UmbracoContext * Begin removing usage of IPublishedSnapshot from PublishedContentExtensions * Fix PublishedContentExtensions.cs * Don't use snapshots in delivery media api * Use IPublishedMediaCache in QueryMediaApiController * Remove more usages of IPublishedSnapshotAccessor * Comment out tests * Remove more usages of PublishedSnapshotAccessor * Remove PublishedSnapshot from property * Fixed test build * Fix errors * Fix some tests * Delete NuCache 🎉 * Implement DatabaseCacheRebuilder * Remove usage of IPublishedSnapshotService * Remove IPublishedSnapshotService * Remove TestPublishedSnapshotAccessor and make tests build * Don't test Snapshot cachelevel It's no longer supported * Fix BlockEditorConverter Element != Element document type * Remember to set cachemanager * Fix RichTextParserTests * Implement TryGetLevel on INavigationQueryService * Fake level and obsolete it in PublishedContent * Remove ChildrenForAllCultures * Hack Path property on PublishedContent * Remove usages of IPublishedSnapshot in tests * More ConvertersTests * Add hybrid cache to integration tests We can actually do this now because we no longer save files on disk * Rename IPublishedSnapshotRebuilder to ICacheRebuilder * Comment out tests * V15: Replacing the usages of Parent (navigation data) from IPublishedContent (#17125) * Fix .Parent references in PublishedContentExtensions * Add missing methods to FriendlyPublishedContentExtensions (ones that you were able to call on the content directly as they now require extra params) * Fix references from the extension methods * Fix dependencies in tests * Replace IPublishedSnapshotAccessor with the content cache in tests * Resolving more .Parent references * Fix unit tests * Obsolete and use extension methods * Remove private method and use extension instead * Moving code around * Fix tests * Fix more references * Cleanup * Fix more usages * Resolve merge conflict * Fix tests * Cleanup * Fix more tests * Fixed unit tests * Cleanup * Replace last usages --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove usage of IPublishedSnapshotAccessor from IRequestItemProvider * Post merge fixup * Remo IPublishedSnapshot * Add HasAny to IDocumentUrlService * Fix TextBuilder * Fix modelsbuilder tests * Use explicit types * Implement GetByContentType * Support element types in PublishedContentTypeCache * Run enlistments before publishing notifications * Fix elements cache refreshing * Implement GetByUdi * Implement GetAtRoot * Implement GetByRoute * Reimplement GetRouteById * Fix blocks unit tests * Initialize domain cache on boot * Only return routes with domains on non default lanauges * V15: Replacing the usages of `Children` (navigation data) from `IPublishedContent` (#17159) * Update params in PublishedContentExtensions to the general interfaces for the published cache and navigation service, so that we can use the extension methods on both documents and media * Introduce GetParent() which uses the right services * Fix obsolete message on .Parent * Obsolete .Children * Fix usages of Children for ApiMediaQueryService * Fix usage in internal * Fix usages in views * Fix indentation * Fix issue with delete language * Update nuget pacakges * Clear elements cache when content is deleted instead of trying to update it * Reset publishedModelFactory * Fixed publishing --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
2024-10-01 15:03:02 +02:00
// using System.Collections.Generic;
// using System.Linq;
// using Moq;
// using NUnit.Framework;
// using Umbraco.Cms.Core.Models;
// using Umbraco.Cms.Core.Models.PublishedContent;
// using Umbraco.Cms.Core.PropertyEditors;
// using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
// using Umbraco.Cms.Core.Services;
// using Umbraco.Cms.Infrastructure.PublishedCache;
// using Umbraco.Cms.Tests.Common.Builders;
// using Umbraco.Cms.Tests.Common.Builders.Extensions;
// using Umbraco.Cms.Tests.UnitTests.TestHelpers;
// using Umbraco.Extensions;
//
// namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.PublishedCache;
//
// FIXME: Reintroduce if relevant
// [TestFixture]
// public class PublishedContentLanguageVariantTests : PublishedSnapshotServiceTestBase
// {
// [SetUp]
// public override void Setup()
// {
// base.Setup();
//
// var dataTypes = GetDefaultDataTypes();
// var cache = CreateCache(dataTypes, out var contentTypes);
//
// InitializedCache(cache, contentTypes, dataTypes);
// }
//
// protected override PropertyValueConverterCollection PropertyValueConverterCollection
// {
// get
// {
// var collection = base.PropertyValueConverterCollection;
// return new PropertyValueConverterCollection(() => collection.Append(new TestNoValueValueConverter()));
// }
// }
//
// private class TestNoValueValueConverter : SimpleTinyMceValueConverter
// {
// public override bool IsConverter(IPublishedPropertyType propertyType)
// => propertyType.Alias == "noprop";
//
// // for this test, we return false for IsValue for this property
// public override bool? IsValue(object value, PropertyValueLevel level) => false;
// }
//
// /// <summary>
// /// Override to mock localization service
// /// </summary>
// /// <returns></returns>
// protected override ServiceContext CreateServiceContext(IContentType[] contentTypes, IMediaType[] mediaTypes, IDataType[] dataTypes)
// {
// var serviceContext = base.CreateServiceContext(contentTypes, mediaTypes, dataTypes);
//
// var localizationService = Mock.Get(serviceContext.LocalizationService);
//
// var languages = new List<Language>
// {
// new("en-US", "English (United States)") { Id = 1, IsDefault = true },
// new("fr", "French") { Id = 2 },
// new("es", "Spanish") { Id = 3, FallbackIsoCode = "en-US" },
// new("it", "Italian") { Id = 4, FallbackIsoCode = "es" },
// new("de", "German") { Id = 5 },
// new Language("da", "Danish") { Id = 6, FallbackIsoCode = "no" },
// new Language("sv", "Swedish") { Id = 7, FallbackIsoCode = "da" },
// new Language("no", "Norweigan") { Id = 8, FallbackIsoCode = "sv" },
// new Language("nl", "Dutch") { Id = 9, FallbackIsoCode = "en-US" },
// };
//
// localizationService.Setup(x => x.GetAllLanguages()).Returns(languages);
// localizationService.Setup(x => x.GetLanguageById(It.IsAny<int>()))
// .Returns((int id) => languages.SingleOrDefault(y => y.Id == id));
// localizationService.Setup(x => x.GetLanguageByIsoCode(It.IsAny<string>()))
// .Returns((string c) => languages.SingleOrDefault(y => y.IsoCode == c));
//
// return serviceContext;
// }
//
// /// <summary>
// /// Creates a content cache
// /// </summary>
// /// <param name="dataTypes"></param>
// /// <param name="contentTypes"></param>
// /// <returns></returns>
// /// <remarks>
// /// Builds a content hierarchy of 3 nodes, each has a different set of cultural properties.
// /// The first 2 share the same content type, the last one is a different content type.
// /// NOTE: The content items themselves are 'Invariant' but their properties are 'Variant' by culture.
// /// Normally in Umbraco this is prohibited but our APIs and database do actually support that behavior.
// /// It is simpler to have these tests run this way, else we would need to use WithCultureInfos
// /// for each item and pass in name values for all cultures we are supporting and then specify the
// /// default VariationContextAccessor.VariationContext value to be a default culture instead of "".
// /// </remarks>
// private IEnumerable<ContentNodeKit> CreateCache(IDataType[] dataTypes, out ContentType[] contentTypes)
// {
// var result = new List<ContentNodeKit>();
//
// var propertyDataTypes = new Dictionary<string, IDataType>
// {
// // we only have one data type for this test which will be resolved with string empty.
// [string.Empty] = dataTypes[0],
// };
//
// var contentType1 = new ContentType(ShortStringHelper, -1);
//
// var item1Data = new ContentDataBuilder()
// .WithName("Content 1")
// .WithProperties(new PropertyDataBuilder()
// .WithPropertyData("welcomeText", "Welcome")
// .WithPropertyData("welcomeText", "Welcome", "en-US")
// .WithPropertyData("welcomeText", "Willkommen", "de")
// .WithPropertyData("welcomeText", "Welkom", "nl")
// .WithPropertyData("welcomeText2", "Welcome")
// .WithPropertyData("welcomeText2", "Welcome", "en-US")
// .WithPropertyData("noprop", "xxx")
// .Build())
//
// // build with a dynamically created content type
// .Build(ShortStringHelper, propertyDataTypes, contentType1, "ContentType1");
//
// var item1 = ContentNodeKitBuilder.CreateWithContent(
// contentType1.Id,
// 1,
// "-1,1",
// draftData: item1Data,
// publishedData: item1Data);
//
// result.Add(item1);
//
// var item2Data = new ContentDataBuilder()
// .WithName("Content 2")
// .WithProperties(new PropertyDataBuilder()
// .WithPropertyData("welcomeText", "Welcome")
// .WithPropertyData("welcomeText", "Welcome", "en-US")
// .WithPropertyData("numericField", 123)
// .WithPropertyData("numericField", 123, "en-US")
// .WithPropertyData("noprop", "xxx")
// .Build())
//
// // build while dynamically updating the same content type
// .Build(ShortStringHelper, propertyDataTypes, contentType1);
//
// var item2 = ContentNodeKitBuilder.CreateWithContent(
// contentType1.Id,
// 2,
// "-1,1,2",
// parentContentId: 1,
// draftData: item2Data,
// publishedData: item2Data);
//
// result.Add(item2);
//
// var contentType2 = new ContentType(ShortStringHelper, -1);
//
// var item3Data = new ContentDataBuilder()
// .WithName("Content 3")
// .WithProperties(new PropertyDataBuilder()
// .WithPropertyData("prop3", "Oxxo")
// .WithPropertyData("prop3", "Oxxo", "en-US")
// .Build())
//
// // build with a dynamically created content type
// .Build(ShortStringHelper, propertyDataTypes, contentType2, "ContentType2");
//
// var item3 = ContentNodeKitBuilder.CreateWithContent(
// contentType2.Id,
// 3,
// "-1,1,2,3",
// parentContentId: 2,
// draftData: item3Data,
// publishedData: item3Data);
//
// result.Add(item3);
//
// contentTypes = new[] { contentType1, contentType2 };
//
// return result;
// }
//
// [Test]
// public void Can_Get_Content_For_Populated_Requested_Language()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText", "en-US");
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Can_Get_Content_For_Populated_Requested_Non_Default_Language()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText", "de");
// Assert.AreEqual("Willkommen", value);
// }
//
// [Test]
// public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_Without_Fallback()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText", "fr");
// Assert.IsNull(value);
// }
//
// [Test]
// public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Unless_Requested()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText", "es");
// Assert.IsNull(value);
// }
//
// [Test]
// public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(PublishedValueFallback, "welcomeText", "es", fallback: Fallback.ToLanguage);
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Over_Two_Levels()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(PublishedValueFallback, "welcomeText", "it", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors));
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Do_Not_GetContent_For_Unpopulated_Requested_Language_With_Fallback_Over_That_Loops()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText", "no", fallback: Fallback.ToLanguage);
// Assert.IsNull(value);
// }
//
// [Test]
// public void Can_Get_Content_For_Unpopulated_Requested_DefaultLanguage_With_Fallback()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First();
// var value = content.Value(PublishedValueFallback, "welcomeText", "fr", fallback: Fallback.ToDefaultLanguage);
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Do_Not_Get_Content_Recursively_Unless_Requested()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText2");
// Assert.IsNull(value);
// }
//
// [Test]
// public void Can_Get_Content_Recursively()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
// var value = content.Value(PublishedValueFallback, "welcomeText2", fallback: Fallback.ToAncestors);
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Do_Not_Get_Content_Recursively_Unless_Requested2()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First().Children.First();
// Assert.IsNull(content.GetProperty("welcomeText2"));
// var value = content.Value(Mock.Of<IPublishedValueFallback>(), "welcomeText2");
// Assert.IsNull(value);
// }
//
// [Test]
// public void Can_Get_Content_Recursively2()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First().Children.First();
// Assert.IsNull(content.GetProperty("welcomeText2"));
// var value = content.Value(PublishedValueFallback, "welcomeText2", fallback: Fallback.ToAncestors);
// Assert.AreEqual("Welcome", value);
// }
//
// [Test]
// public void Can_Get_Content_Recursively3()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First().Children.First();
// Assert.IsNull(content.GetProperty("noprop"));
// var value = content.Value(PublishedValueFallback, "noprop", fallback: Fallback.ToAncestors);
//
// // property has no value - based on the converter
// // but we still get the value (ie, the converter would do something)
// Assert.AreEqual("xxx", value.ToString());
// }
//
// [Test]
// public void Can_Get_Content_With_Recursive_Priority()
// {
// VariationContextAccessor.VariationContext = new VariationContext("nl");
//
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
//
// var value = content.Value(PublishedValueFallback, "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);
// }
//
// [Test]
// public void Can_Get_Content_With_Fallback_Language_Priority()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
//
// var value = content.Value(PublishedValueFallback, "welcomeText", "nl", fallback: Fallback.ToLanguage);
// var numericValue = content.Value(PublishedValueFallback, "numericField", "nl", fallback: Fallback.ToLanguage);
//
// // No Dutch value is directly assigned. Check has fallen back to English value from language variant.
// Assert.AreEqual("Welcome", value);
// Assert.AreEqual(123, numericValue);
// }
//
// [Test]
// public void Can_Get_Content_For_Property_With_Fallback_Language_Priority()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
//
// var value = content.GetProperty("welcomeText")!.Value(PublishedValueFallback, "nl", fallback: Fallback.ToLanguage);
// var numericValue = content.GetProperty("numericField")!.Value(PublishedValueFallback, "nl", fallback: Fallback.ToLanguage);
//
// // No Dutch value is directly assigned. Check has fallen back to English value from language variant.
// Assert.AreEqual("Welcome", value);
// Assert.AreEqual(123, numericValue);
// }
//
// [Test]
// public void Throws_For_Non_Supported_Fallback()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
//
// Assert.Throws<NotSupportedException>(() =>
// content.Value(PublishedValueFallback, "welcomeText", "nl", fallback: Fallback.To(999)));
// }
//
// [Test]
// public void Can_Fallback_To_Default_Value()
// {
// var snapshot = GetPublishedSnapshot();
// var content = snapshot.Content.GetAtRoot().First().Children.First();
//
// // no Dutch value is assigned, so getting null
// var value = content.Value(PublishedValueFallback, "welcomeText", "nl");
// Assert.IsNull(value);
//
// // even if we 'just' provide a default value
// value = content.Value(PublishedValueFallback, "welcomeText", "nl", defaultValue: "woop");
// Assert.IsNull(value);
//
// // but it works with proper fallback settings
// value = content.Value(PublishedValueFallback, "welcomeText", "nl", fallback: Fallback.ToDefaultValue, defaultValue: "woop");
// Assert.AreEqual("woop", value);
// }
// }