From 45a6789fded5229db30f3b5063edab4ff181f0bb Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 6 Dec 2018 12:17:40 +1100 Subject: [PATCH] Added a failing test --- .../Services/ContentServiceTagsTests.cs | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs b/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs index 8bb61fc186..196af5c0bd 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs @@ -256,6 +256,102 @@ namespace Umbraco.Tests.Services Assert.IsFalse(enTagGroup.Any(x => x.Text == "plus")); } + [Test] + public void TagsCanBecomeInvariantByPropertyType() + { + var languageService = ServiceContext.LocalizationService; + languageService.Save(new Language("fr-FR")); // en-US is already there + + var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; + + var contentService = ServiceContext.ContentService; + var contentTypeService = ServiceContext.ContentTypeService; + var tagService = ServiceContext.TagService; + var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); + PropertyType propertyType; + contentType.PropertyGroups.First().PropertyTypes.Add( + propertyType = new PropertyType("test", ValueStorageType.Ntext, "tags") + { + DataTypeId = 1041, + Variations = ContentVariation.Culture + }); + contentType.Variations = ContentVariation.Culture; + contentTypeService.Save(contentType); + + IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); + content1.SetCultureName("name-fr", "fr-FR"); + content1.SetCultureName("name-en", "en-US"); + content1.AssignTags("tags", new[] { "hello", "world", "some", "tags", "plus" }, culture: "fr-FR"); + content1.AssignTags("tags", new[] { "hello", "world", "another", "one" }, culture: "en-US"); + contentService.SaveAndPublish(content1); + + propertyType.Variations = ContentVariation.Nothing; + contentTypeService.Save(contentType); + + // changes + content1 = contentService.GetById(content1.Id); + + // property value has been moved from en-US to invariant, fr-FR tags are gone + Assert.IsEmpty(content1.Properties["tags"].GetTagsValue("fr-FR")); + Assert.IsEmpty(content1.Properties["tags"].GetTagsValue("en-US")); + + var tags = content1.Properties["tags"].GetTagsValue().ToArray(); + Assert.AreEqual(4, tags.Length); + Assert.Contains("one", tags); + Assert.AreEqual(-1, tags.IndexOf("plus")); + + // tags have been copied from en-US to invariant, fr-FR tags are gone + var tagGroups = tagService.GetAllTags(culture: "*").GroupBy(x => x.LanguageId); + foreach (var tag in tagService.GetAllTags("*")) + Console.WriteLine($"{tag.Group}:{tag.Text} {tag.LanguageId}"); + Assert.AreEqual(1, tagGroups.Count()); + + var enTagGroup = tagGroups.FirstOrDefault(x => x.Key == null); + Assert.IsNotNull(enTagGroup); + Assert.AreEqual(4, enTagGroup.Count()); + Assert.IsTrue(enTagGroup.Any(x => x.Text == "one")); + Assert.IsFalse(enTagGroup.Any(x => x.Text == "plus")); + } + + [Test] + public void TagsCanBecomeInvariantByPropertyTypeAndBackToVariant() + { + var languageService = ServiceContext.LocalizationService; + languageService.Save(new Language("fr-FR")); // en-US is already there + + var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; + + var contentService = ServiceContext.ContentService; + var contentTypeService = ServiceContext.ContentTypeService; + var tagService = ServiceContext.TagService; + var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); + PropertyType propertyType; + contentType.PropertyGroups.First().PropertyTypes.Add( + propertyType = new PropertyType("test", ValueStorageType.Ntext, "tags") + { + DataTypeId = 1041, + Variations = ContentVariation.Culture + }); + contentType.Variations = ContentVariation.Culture; + contentTypeService.Save(contentType); + + IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); + content1.SetCultureName("name-fr", "fr-FR"); + content1.SetCultureName("name-en", "en-US"); + content1.AssignTags("tags", new[] { "hello", "world", "some", "tags", "plus" }, culture: "fr-FR"); + content1.AssignTags("tags", new[] { "hello", "world", "another", "one" }, culture: "en-US"); + contentService.SaveAndPublish(content1); + + propertyType.Variations = ContentVariation.Nothing; + contentTypeService.Save(contentType); + + //fixme: This throws due to index violations + propertyType.Variations = ContentVariation.Culture; + contentTypeService.Save(contentType); + + //TODO: Assert results + } + [Test] public void TagsAreUpdatedWhenContentIsTrashedAndUnTrashed_One() {