2024-04-04 09:40:06 +02:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
2024-04-08 14:55:46 +02:00
|
|
|
using Umbraco.Cms.Core.Models.Entities;
|
2025-06-24 13:43:34 +02:00
|
|
|
using Umbraco.Cms.Core.Serialization;
|
2024-04-08 14:55:46 +02:00
|
|
|
using Umbraco.Cms.Core.Services;
|
2024-04-04 09:40:06 +02:00
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests for the content blueprint editing service. Please notice that a lot of the functional tests are covered by the content
|
|
|
|
|
/// editing service tests, since these services share the same base implementation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ContentBlueprintEditingServiceTests : ContentEditingServiceTestsBase
|
|
|
|
|
{
|
2024-04-08 14:55:46 +02:00
|
|
|
private IContentBlueprintContainerService ContentBlueprintContainerService => GetRequiredService<IContentBlueprintContainerService>();
|
|
|
|
|
|
|
|
|
|
private IEntityService EntityService => GetRequiredService<IEntityService>();
|
|
|
|
|
|
2025-06-24 13:43:34 +02:00
|
|
|
private IJsonSerializer JsonSerializer => GetRequiredService<IJsonSerializer>();
|
|
|
|
|
|
2024-04-04 09:40:06 +02:00
|
|
|
private async Task<IContent> CreateInvariantContentBlueprint()
|
|
|
|
|
{
|
|
|
|
|
var contentType = CreateInvariantContentType();
|
|
|
|
|
|
|
|
|
|
var createModel = new ContentBlueprintCreateModel
|
|
|
|
|
{
|
|
|
|
|
ContentTypeKey = contentType.Key,
|
|
|
|
|
ParentKey = Constants.System.RootKey,
|
2025-04-23 14:54:51 +02:00
|
|
|
Variants = [new VariantModel { Name = "Initial Blueprint Name" }],
|
|
|
|
|
Properties =
|
|
|
|
|
[
|
2024-04-04 09:40:06 +02:00
|
|
|
new PropertyValueModel { Alias = "title", Value = "The initial title" },
|
2025-04-23 14:54:51 +02:00
|
|
|
new PropertyValueModel { Alias = "text", Value = "The initial text" }
|
|
|
|
|
],
|
2024-04-04 09:40:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = await ContentBlueprintEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
|
|
|
|
Assert.IsTrue(result.Success);
|
|
|
|
|
return result.Result.Content!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<IContent> CreateVariantContentBlueprint()
|
|
|
|
|
{
|
|
|
|
|
var contentType = await CreateVariantContentType();
|
|
|
|
|
|
|
|
|
|
var createModel = new ContentBlueprintCreateModel
|
|
|
|
|
{
|
|
|
|
|
ContentTypeKey = contentType.Key,
|
|
|
|
|
ParentKey = Constants.System.RootKey,
|
2025-04-23 14:54:51 +02:00
|
|
|
Properties =
|
|
|
|
|
[
|
2024-04-04 09:40:06 +02:00
|
|
|
new PropertyValueModel { Alias = "invariantTitle", Value = "The initial invariant title" },
|
2025-04-23 14:54:51 +02:00
|
|
|
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 Blueprint English Name" },
|
|
|
|
|
new VariantModel { Culture = "da-DK", Name = "Initial Blueprint Danish Name" }
|
|
|
|
|
],
|
2024-04-04 09:40:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = await ContentBlueprintEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
|
|
|
|
Assert.IsTrue(result.Success);
|
|
|
|
|
return result.Result.Content!;
|
|
|
|
|
}
|
2024-04-08 14:55:46 +02:00
|
|
|
|
|
|
|
|
private ContentBlueprintCreateModel SimpleContentBlueprintCreateModel(Guid blueprintKey, Guid? containerKey)
|
|
|
|
|
{
|
|
|
|
|
var createModel = new ContentBlueprintCreateModel
|
|
|
|
|
{
|
|
|
|
|
Key = blueprintKey,
|
|
|
|
|
ContentTypeKey = ContentType.Key,
|
|
|
|
|
ParentKey = containerKey,
|
2025-04-23 14:54:51 +02:00
|
|
|
Variants = [new VariantModel { Name = "Blueprint #1" }],
|
|
|
|
|
Properties =
|
|
|
|
|
[
|
2024-04-08 14:55:46 +02:00
|
|
|
new PropertyValueModel { Alias = "title", Value = "The title value" },
|
2025-06-24 13:43:34 +02:00
|
|
|
new PropertyValueModel { Alias = "author", Value = "The author value" },
|
|
|
|
|
],
|
2024-04-08 14:55:46 +02:00
|
|
|
};
|
|
|
|
|
return createModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContentBlueprintUpdateModel SimpleContentBlueprintUpdateModel()
|
|
|
|
|
{
|
|
|
|
|
var createModel = new ContentBlueprintUpdateModel
|
|
|
|
|
{
|
2025-04-23 14:54:51 +02:00
|
|
|
Variants = [new VariantModel { Name = "Blueprint #1 updated" }],
|
|
|
|
|
Properties =
|
|
|
|
|
[
|
2024-04-08 14:55:46 +02:00
|
|
|
new PropertyValueModel { Alias = "title", Value = "The title value updated" },
|
|
|
|
|
new PropertyValueModel { Alias = "author", Value = "The author value updated" }
|
2025-06-24 13:43:34 +02:00
|
|
|
],
|
2024-04-08 14:55:46 +02:00
|
|
|
};
|
|
|
|
|
return createModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEntitySlim[] GetBlueprintChildren(Guid? containerKey)
|
2025-06-24 13:43:34 +02:00
|
|
|
=> EntityService.GetPagedChildren(containerKey, [UmbracoObjectTypes.DocumentBlueprintContainer], UmbracoObjectTypes.DocumentBlueprint, 0, 100, out _).ToArray();
|
2024-04-04 09:40:06 +02:00
|
|
|
}
|
2025-06-24 13:43:34 +02:00
|
|
|
|