2024-09-10 00:49:18 +09:00
|
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentPublishing;
|
2024-09-24 09:39:23 +02:00
|
|
|
|
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2024-09-24 09:39:23 +02:00
|
|
|
|
using Umbraco.Cms.Core.Services.ContentTypeEditing;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
2024-09-24 09:39:23 +02:00
|
|
|
|
using Umbraco.Cms.Tests.Common.TestHelpers;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class UmbracoIntegrationTestWithContentEditing : UmbracoIntegrationTest
|
|
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected IContentTypeEditingService ContentTypeEditingService => GetRequiredService<IContentTypeEditingService>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
protected ITemplateService TemplateService => GetRequiredService<ITemplateService>();
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private IContentEditingService ContentEditingService => (IContentEditingService)GetRequiredService<IContentEditingService>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private IContentPublishingService ContentPublishingService => (IContentPublishingService)GetRequiredService<IContentPublishingService>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected int TemplateId { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected ContentCreateModel Subpage1 { get; private set; }
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
protected ContentCreateModel Subpage2 { get; private set; }
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected ContentCreateModel PublishedTextPage { get; private set; }
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
protected ContentCreateModel Textpage { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected ContentScheduleCollection ContentSchedule { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected CultureAndScheduleModel CultureAndSchedule { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected int TextpageId { get; private set; }
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected int PublishedTextPageId { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected int Subpage1Id { get; private set; }
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
protected int Subpage2Id { get; private set; }
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected ContentTypeCreateModel ContentTypeCreateModel { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected ContentTypeUpdateModel ContentTypeUpdateModel { get; private set; }
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
protected IContentType ContentType { get; private set; }
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
|
public new void Setup() => CreateTestData();
|
|
|
|
|
|
|
|
|
|
|
|
protected async void CreateTestData()
|
|
|
|
|
|
{
|
|
|
|
|
|
// NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested.
|
|
|
|
|
|
var template = TemplateBuilder.CreateTextPageTemplate("defaultTemplate");
|
|
|
|
|
|
await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey);
|
2024-09-24 09:39:23 +02:00
|
|
|
|
TemplateId = template.Id;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
// Create and Save ContentType "umbTextpage" -> 1051 (template), 1052 (content type)
|
2024-09-24 09:39:23 +02:00
|
|
|
|
ContentTypeCreateModel = ContentTypeEditingBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateKey: template.Key);
|
|
|
|
|
|
var contentTypeAttempt = await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(contentTypeAttempt.Success);
|
|
|
|
|
|
|
|
|
|
|
|
var contentTypeResult = contentTypeAttempt.Result;
|
2024-10-07 11:11:22 +02:00
|
|
|
|
ContentTypeUpdateModel = ContentTypeUpdateHelper.CreateContentTypeUpdateModel(contentTypeResult); ContentTypeUpdateModel.AllowedContentTypes = new[]
|
2024-09-24 09:39:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
new ContentTypeSort(contentTypeResult.Key, 0, ContentTypeCreateModel.Alias),
|
|
|
|
|
|
};
|
|
|
|
|
|
var updatedContentTypeResult = await ContentTypeEditingService.UpdateAsync(contentTypeResult, ContentTypeUpdateModel, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(updatedContentTypeResult.Success);
|
|
|
|
|
|
ContentType = updatedContentTypeResult.Result;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
// Create and Save Content "Homepage" based on "umbTextpage" -> 1053
|
2024-09-24 09:39:23 +02:00
|
|
|
|
Textpage = ContentEditingBuilder.CreateSimpleContent(ContentType.Key);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
var createContentResultTextPage = await ContentEditingService.CreateAsync(Textpage, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(createContentResultTextPage.Success);
|
|
|
|
|
|
|
|
|
|
|
|
if (!Textpage.Key.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("The content page key is null.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (createContentResultTextPage.Result.Content != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
TextpageId = createContentResultTextPage.Result.Content.Id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sets the culture and schedule for the content, in this case, we are publishing immediately for all cultures
|
|
|
|
|
|
ContentSchedule = new ContentScheduleCollection();
|
|
|
|
|
|
CultureAndSchedule = new CultureAndScheduleModel
|
|
|
|
|
|
{
|
|
|
|
|
|
CulturesToPublishImmediately = new HashSet<string> { "*" }, Schedules = ContentSchedule,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
|
2024-09-24 09:39:23 +02:00
|
|
|
|
PublishedTextPage = ContentEditingBuilder.CreateSimpleContent(ContentType.Key, "Published Page");
|
|
|
|
|
|
var createContentResultPublishPage = await ContentEditingService.CreateAsync(PublishedTextPage, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(createContentResultPublishPage.Success);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
if (!PublishedTextPage.Key.HasValue)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("The content page key is null.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
if (createContentResultPublishPage.Result.Content != null)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
PublishedTextPageId = createContentResultPublishPage.Result.Content.Id;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
var publishResult = await ContentPublishingService.PublishAsync(PublishedTextPage.Key.Value, CultureAndSchedule, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(publishResult.Success);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
// Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055
|
2024-09-24 09:39:23 +02:00
|
|
|
|
Subpage1 = ContentEditingBuilder.CreateSimpleContent(ContentType.Key, "Text Page 1", Textpage.Key);
|
|
|
|
|
|
var createContentResultSubPage1 = await ContentEditingService.CreateAsync(Subpage1, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(createContentResultSubPage1.Success);
|
|
|
|
|
|
if (!Subpage1.Key.HasValue)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("The content page key is null.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
if (createContentResultSubPage1.Result.Content != null)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
Subpage1Id = createContentResultSubPage1.Result.Content.Id;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
Subpage2 = ContentEditingBuilder.CreateSimpleContent(ContentType.Key, "Text Page 2", Textpage.Key);
|
|
|
|
|
|
var createContentResultSubPage2 = await ContentEditingService.CreateAsync(Subpage2, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(createContentResultSubPage2.Success);
|
|
|
|
|
|
if (!Subpage2.Key.HasValue)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("The content page key is null.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
if (createContentResultSubPage2.Result.Content != null)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
Subpage2Id = createContentResultSubPage2.Result.Content.Id;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|