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)
This commit is contained in:
Elitsa Marinovska
2022-10-13 08:59:53 +02:00
committed by GitHub
parent 9f6d5e9543
commit cdc994dd8e
2 changed files with 74 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ public static class PropertyTagsExtensions
: dataTypeService.GetDataType(property.PropertyType.DataTypeId)?.Configuration;
TagConfiguration? configuration = ConfigurationEditor.ConfigurationAs<TagConfiguration>(configurationObject);
if (configuration?.Delimiter == default && configuration?.Delimiter is not null)
if (configuration is not null && configuration.Delimiter == default)
{
configuration.Delimiter = tagAttribute.Delimiter;
}

View File

@@ -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)
{