Service refactoring to "fully" enable segments (#19114)

* Refactor serverside content editing to support all variance combinations

* Fix build errors

* Reintroduce the tests ignored by #19060

---------

Co-authored-by: Mads Rasmussen <madsr@hey.com>
This commit is contained in:
Kenn Jacobsen
2025-04-23 14:54:51 +02:00
committed by GitHub
parent 53b94a8f57
commit 2cf28271cd
46 changed files with 1321 additions and 1028 deletions

View File

@@ -117,13 +117,16 @@ public abstract class ContentEditingServiceTestsBase : UmbracoIntegrationTestWit
{
ContentTypeKey = contentType.Key,
ParentKey = Constants.System.RootKey,
InvariantName = "Initial Name",
Variants =
[
new VariantModel { Name = "Initial Name" }
],
TemplateKey = templates.FirstOrDefault()?.Key,
InvariantProperties = new[]
{
Properties =
[
new PropertyValueModel { Alias = "title", Value = "The initial title" },
new PropertyValueModel { Alias = "text", Value = "The initial text" },
},
new PropertyValueModel { Alias = "text", Value = "The initial text" }
],
};
var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
@@ -139,31 +142,17 @@ public abstract class ContentEditingServiceTestsBase : UmbracoIntegrationTestWit
{
ContentTypeKey = contentType.Key,
ParentKey = Constants.System.RootKey,
InvariantProperties = new[]
{
Properties =
[
new PropertyValueModel { Alias = "invariantTitle", Value = "The initial invariant title" },
},
Variants = new[]
{
new VariantModel
{
Culture = "en-US",
Name = "Initial English Name",
Properties = new[]
{
new PropertyValueModel { Alias = "variantTitle", Value = "The initial English title" },
},
},
new VariantModel
{
Culture = "da-DK",
Name = "Initial Danish Name",
Properties = new[]
{
new PropertyValueModel { Alias = "variantTitle", Value = "The initial Danish title" },
},
},
},
new PropertyValueModel { Alias = "variantTitle", Value = "The initial English title", Culture = "en-US" },
new PropertyValueModel { Alias = "variantTitle", Value = "The initial Danish title", Culture = "da-DK" }
],
Variants =
[
new VariantModel { Culture = "en-US", Name = "Initial English Name" },
new VariantModel { Culture = "da-DK", Name = "Initial Danish Name" }
]
};
var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
@@ -179,40 +168,71 @@ public abstract class ContentEditingServiceTestsBase : UmbracoIntegrationTestWit
{
ContentTypeKey = contentType.Key,
ParentKey = Constants.System.RootKey,
InvariantProperties = new[]
{
Properties =
[
new PropertyValueModel { Alias = "invariantTitle", Value = "The initial invariant title" },
},
Variants = new[]
{
new VariantModel
{
Segment = null,
Name = "The Name",
Properties = new[]
{
new PropertyValueModel { Alias = "variantTitle", Value = "The initial default title" },
},
},
new VariantModel
{
Segment = "seg-1",
Name = "The Name",
Properties = new[]
{
new PropertyValueModel { Alias = "variantTitle", Value = "The initial seg-1 title" },
},
},
new VariantModel
{
Segment = "seg-2",
Name = "The Name",
Properties = new[]
{
new PropertyValueModel { Alias = "variantTitle", Value = "The initial seg-2 title" },
},
},
},
new PropertyValueModel { Alias = "variantTitle", Value = "The initial default title" },
new PropertyValueModel { Alias = "variantTitle", Value = "The initial seg-1 title", Segment = "seg-1" },
new PropertyValueModel { Alias = "variantTitle", Value = "The initial seg-2 title", Segment = "seg-2" }
],
Variants =
[
new VariantModel { Segment = null, Name = "The Name" },
new VariantModel { Segment = "seg-1", Name = "The Name" },
new VariantModel { Segment = "seg-2", Name = "The Name" }
],
};
var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
Assert.IsTrue(result.Success);
return result.Result.Content!;
}
protected async Task<IContent> CreateCultureAndSegmentVariantContent(ContentVariation otherTitleVariation)
{
var contentType = await CreateVariantContentType(ContentVariation.CultureAndSegment);
var propertyType = contentType.PropertyTypes.First(pt => pt.Alias == "invariantTitle");
propertyType.Alias = "otherTitle";
propertyType.Variations = otherTitleVariation;
ContentTypeService.Save(contentType);
IEnumerable<PropertyValueModel> otherTitleValues = otherTitleVariation switch
{
ContentVariation.Culture =>
[
new PropertyValueModel { Alias = "otherTitle", Value = "The initial other English title", Culture = "en-US" },
new PropertyValueModel { Alias = "otherTitle", Value = "The initial other Danish title", Culture = "da-DK" },
],
ContentVariation.Segment =>
[
new PropertyValueModel { Alias = "otherTitle", Value = "The initial other default title" },
new PropertyValueModel { Alias = "otherTitle", Value = "The initial other seg-1 title", Segment = "seg-1" },
new PropertyValueModel { Alias = "otherTitle", Value = "The initial other seg-2 title", Segment = "seg-2" }
],
_ => throw new ArgumentOutOfRangeException(nameof(otherTitleVariation))
};
var createModel = new ContentCreateModel
{
ContentTypeKey = contentType.Key,
ParentKey = Constants.System.RootKey,
Properties = otherTitleValues.Union([
new () { Alias = "variantTitle", Value = "The initial title in English", Culture = "en-US" },
new () { Alias = "variantTitle", Value = "The initial seg-1 title in English", Culture = "en-US", Segment = "seg-1" },
new () { Alias = "variantTitle", Value = "The initial seg-2 title in English", Culture = "en-US", Segment = "seg-2" },
new () { Alias = "variantTitle", Value = "The initial title in Danish", Culture = "da-DK" },
new () { Alias = "variantTitle", Value = "The initial seg-1 title in Danish", Culture = "da-DK", Segment = "seg-1" },
new () { Alias = "variantTitle", Value = "The initial seg-2 title in Danish", Culture = "da-DK", Segment = "seg-2" }
]),
Variants =
[
new VariantModel { Name = "The Name", Culture = "en-US", Segment = null },
new VariantModel { Name = "The Name", Culture = "en-US", Segment = "seg-1" },
new VariantModel { Name = "The Name", Culture = "en-US", Segment = "seg-2" },
new VariantModel { Name = "The Name", Culture = "da-DK", Segment = null },
new VariantModel { Name = "The Name", Culture = "da-DK", Segment = "seg-1" },
new VariantModel { Name = "The Name", Culture = "da-DK", Segment = "seg-2" },
],
};
var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);