From cdc994dd8ee16f539e0115c514f8b1168f48fd10 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Date: Thu, 13 Oct 2022 08:59:53 +0200 Subject: [PATCH] Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) --- .../Models/PropertyTagsExtensions.cs | 2 +- .../Services/ContentServiceTagsTests.cs | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs index 9ad98d66c0..d36baed604 100644 --- a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs +++ b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs @@ -33,7 +33,7 @@ public static class PropertyTagsExtensions : dataTypeService.GetDataType(property.PropertyType.DataTypeId)?.Configuration; TagConfiguration? configuration = ConfigurationEditor.ConfigurationAs(configurationObject); - if (configuration?.Delimiter == default && configuration?.Delimiter is not null) + if (configuration is not null && configuration.Delimiter == default) { configuration.Delimiter = tagAttribute.Delimiter; } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs index 25e7aa1009..9179b6cd69 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs @@ -638,6 +638,9 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var dataType = DataTypeService.GetDataType(1041); dataType.Configuration = new TagConfiguration { Group = "test", StorageType = TagsStorageType.Csv }; + // updating the data type with the new configuration + DataTypeService.Save(dataType); + var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -822,6 +825,76 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest } } + [Test] + public void Does_Not_Save_Multiple_Tags_As_One_When_CSV_Storage() + { + // Arrange + // set configuration + var dataType = DataTypeService.GetDataType(1041); + dataType.Configuration = new TagConfiguration { Group = "test", StorageType = TagsStorageType.Csv }; + + // updating the data type with the new configuration + DataTypeService.Save(dataType); + + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", + mandatoryProperties: true, defaultTemplateId: template.Id); + CreateAndAddTagsPropertyType(contentType); + + ContentTypeService.Save(contentType); + + IContent content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content"); + content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", + new[] { "hello,world,tags", "new"}); + + ContentService.SaveAndPublish(content); + + // Act + content = ContentService.GetById(content.Id); + var savedTags = content.Properties["tags"].GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer) + .ToArray(); + + // Assert + Assert.AreEqual(4, savedTags.Length); + } + + [Test] + public void Can_Save_Tag_With_Comma_Separated_Values_As_One_When_JSON_Storage() + { + // Arrange + // set configuration + var dataType = DataTypeService.GetDataType(1041); + dataType.Configuration = new TagConfiguration { Group = "test", StorageType = TagsStorageType.Json }; + + // updating the data type with the new configuration + DataTypeService.Save(dataType); + + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", + mandatoryProperties: true, defaultTemplateId: template.Id); + CreateAndAddTagsPropertyType(contentType); + + ContentTypeService.Save(contentType); + + IContent content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content"); + content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", + new[] { "hello,world,tags", "new"}); + + ContentService.SaveAndPublish(content); + + // Act + content = ContentService.GetById(content.Id); + var savedTags = content.Properties["tags"].GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer) + .ToArray(); + + // Assert + Assert.AreEqual(2, savedTags.Length); + } + private PropertyType CreateAndAddTagsPropertyType(ContentType contentType, ContentVariation variations = ContentVariation.Nothing) {