From 2e79a515c9ac83bee24b5354fe3bfb89d4d0819d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Knippers?= Date: Fri, 4 Oct 2019 12:07:05 +0200 Subject: [PATCH] Updated tests --- .../ContentTypeServiceVariantsTests.cs | 82 ++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 2a94ba971e..48bcf3c928 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -124,9 +124,7 @@ namespace Umbraco.Tests.Services public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation, ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared) { var contentType = MockedContentTypes.CreateBasicContentType(); - contentType.Variations = startingContentTypeVariation; - var properties = CreatePropertyCollection(("title", startingContentTypeVariation)); - contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); + contentType.Variations = startingContentTypeVariation; ServiceContext.ContentTypeService.Save(contentType); var contentType2 = MockedContentTypes.CreateBasicContentType("test"); ServiceContext.ContentTypeService.Save(contentType2); @@ -271,6 +269,84 @@ namespace Umbraco.Tests.Services Assert.IsTrue(doc.IsCultureEdited("en-US")); } + [TestCase(ContentVariation.Nothing, ContentVariation.Nothing)] + [TestCase(ContentVariation.Nothing, ContentVariation.Culture)] + [TestCase(ContentVariation.Nothing, ContentVariation.Segment)] + [TestCase(ContentVariation.Nothing, ContentVariation.CultureAndSegment)] + [TestCase(ContentVariation.Culture, ContentVariation.Nothing)] + [TestCase(ContentVariation.Culture, ContentVariation.Culture)] + [TestCase(ContentVariation.Culture, ContentVariation.Segment)] + [TestCase(ContentVariation.Culture, ContentVariation.CultureAndSegment)] + [TestCase(ContentVariation.Segment, ContentVariation.Nothing)] + [TestCase(ContentVariation.Segment, ContentVariation.Culture)] + [TestCase(ContentVariation.Segment, ContentVariation.Segment)] + [TestCase(ContentVariation.Segment, ContentVariation.CultureAndSegment)] + [TestCase(ContentVariation.CultureAndSegment, ContentVariation.Nothing)] + [TestCase(ContentVariation.CultureAndSegment, ContentVariation.Culture)] + [TestCase(ContentVariation.CultureAndSegment, ContentVariation.Segment)] + [TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment)] + public void Preserve_Content_Name_After_Content_Type_Variation_Change(ContentVariation contentTypeVariationFrom, ContentVariation contentTypeVariationTo) + { + var contentType = MockedContentTypes.CreateBasicContentType(); + contentType.Variations = contentTypeVariationFrom; + ServiceContext.ContentTypeService.Save(contentType); + + var invariantContentName = "Content Invariant"; + + var defaultCultureContentName = "Content en-US"; + var defaultCulture = "en-US"; + + var nlContentName = "Content nl-NL"; + var nlCulture = "nl-NL"; + + ServiceContext.LocalizationService.Save(new Language(nlCulture)); + + var includeCultureNames = contentType.Variations.HasFlag(ContentVariation.Culture); + + // Create some content of this content type + IContent doc = MockedContent.CreateBasicContent(contentType); + + doc.Name = invariantContentName; + if (includeCultureNames) + { + Assert.DoesNotThrow(() => doc.SetCultureName(defaultCultureContentName, defaultCulture)); + Assert.DoesNotThrow(() => doc.SetCultureName(nlContentName, nlCulture)); + } else + { + Assert.Throws(() => doc.SetCultureName(defaultCultureContentName, defaultCulture)); + Assert.Throws(() => doc.SetCultureName(nlContentName, nlCulture)); + } + + ServiceContext.ContentService.Save(doc); + doc = ServiceContext.ContentService.GetById(doc.Id); + + AssertAll(); + + // Change variation + contentType.Variations = contentTypeVariationTo; + ServiceContext.ContentService.Save(doc); + doc = ServiceContext.ContentService.GetById(doc.Id); + + AssertAll(); + + void AssertAll() + { + if (includeCultureNames) + { + // Invariant content name is not preserved when content type is set to culture + Assert.AreEqual(defaultCultureContentName, doc.Name); + Assert.AreEqual(doc.Name, doc.GetCultureName(defaultCulture)); + Assert.AreEqual(nlContentName, doc.GetCultureName(nlCulture)); + } + else + { + Assert.AreEqual(invariantContentName, doc.Name); + Assert.AreEqual(null, doc.GetCultureName(defaultCulture)); + Assert.AreEqual(null, doc.GetCultureName(nlCulture)); + } + } + } + [TestCase(ContentVariation.Nothing, ContentVariation.Nothing, true)] [TestCase(ContentVariation.Nothing, ContentVariation.Culture, false)] [TestCase(ContentVariation.Nothing, ContentVariation.Segment, false)]