2024-09-10 00:49:18 +09:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentPublishing;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
|
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.Core.Services.OperationStatus;
|
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
|
|
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
|
|
|
|
public class DocumentHybridCachePropertyTest : UmbracoIntegrationTest
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
|
|
|
|
|
|
|
|
|
|
|
|
private ICacheManager CacheManager => GetRequiredService<ICacheManager>();
|
|
|
|
|
|
|
|
|
|
|
|
private ITemplateService TemplateService => GetRequiredService<ITemplateService>();
|
|
|
|
|
|
|
|
|
|
|
|
private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private IContentTypeEditingService ContentTypeEditingService => GetRequiredService<IContentTypeEditingService>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private IContentPublishingService ContentPublishingService => GetRequiredService<IContentPublishingService>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public async Task Can_Get_Value_From_ContentPicker()
|
|
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Arrange
|
2024-09-10 00:49:18 +09:00
|
|
|
|
var template = TemplateBuilder.CreateTextPageTemplate();
|
|
|
|
|
|
await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey);
|
2024-09-24 09:39:23 +02:00
|
|
|
|
var textPage = await CreateTextPageDocument(template.Key);
|
|
|
|
|
|
var contentPickerDocument = await CreateContentPickerDocument(template.Key, textPage.Key);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Act
|
2024-09-10 00:49:18 +09:00
|
|
|
|
var contentPickerPage = await CacheManager.Content.GetByIdAsync(contentPickerDocument.Id);
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Assert
|
2024-09-10 00:49:18 +09:00
|
|
|
|
IPublishedContent contentPickerValue = (IPublishedContent)contentPickerPage.Value("contentPicker");
|
|
|
|
|
|
Assert.AreEqual(textPage.Key, contentPickerValue.Key);
|
|
|
|
|
|
Assert.AreEqual(textPage.Id, contentPickerValue.Id);
|
|
|
|
|
|
Assert.AreEqual(textPage.Name, contentPickerValue.Name);
|
|
|
|
|
|
Assert.AreEqual("The title value", contentPickerValue.Properties.First(x => x.Alias == "title").GetValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public async Task Can_Get_Value_From_Updated_ContentPicker()
|
|
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Arrange
|
2024-09-10 00:49:18 +09:00
|
|
|
|
var template = TemplateBuilder.CreateTextPageTemplate();
|
|
|
|
|
|
await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey);
|
2024-09-24 09:39:23 +02:00
|
|
|
|
var textPage = await CreateTextPageDocument(template.Key);
|
|
|
|
|
|
var contentPickerDocument = await CreateContentPickerDocument(template.Key, textPage.Key);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
// Get for caching
|
|
|
|
|
|
var notUpdatedContent = await CacheManager.Content.GetByIdAsync(contentPickerDocument.Id);
|
|
|
|
|
|
|
|
|
|
|
|
IPublishedContent contentPickerValue = (IPublishedContent)notUpdatedContent.Value("contentPicker");
|
|
|
|
|
|
Assert.AreEqual("The title value", contentPickerValue.Properties.First(x => x.Alias == "title").GetValue());
|
|
|
|
|
|
|
|
|
|
|
|
// Update content
|
|
|
|
|
|
var updateModel = new ContentUpdateModel
|
|
|
|
|
|
{
|
|
|
|
|
|
InvariantName = "Root Create",
|
|
|
|
|
|
InvariantProperties = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new PropertyValueModel { Alias = "title", Value = "Updated title" },
|
|
|
|
|
|
new PropertyValueModel { Alias = "bodyText", Value = "The body text" }
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var updateResult = await ContentEditingService.UpdateAsync(textPage.Key, updateModel, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(updateResult.Success);
|
|
|
|
|
|
|
|
|
|
|
|
var publishResult = await ContentPublishingService.PublishAsync(
|
|
|
|
|
|
updateResult.Result.Content!.Key,
|
|
|
|
|
|
new CultureAndScheduleModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
CulturesToPublishImmediately = new HashSet<string> {"*"},
|
|
|
|
|
|
Schedules = new ContentScheduleCollection(),
|
|
|
|
|
|
},
|
|
|
|
|
|
Constants.Security.SuperUserKey);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(publishResult);
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Act
|
2024-09-10 00:49:18 +09:00
|
|
|
|
var contentPickerPage = await CacheManager.Content.GetByIdAsync(contentPickerDocument.Id);
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
// Assert
|
|
|
|
|
|
IPublishedContent updatedPickerValue = (IPublishedContent)contentPickerPage.Value("contentPicker");
|
2024-09-10 00:49:18 +09:00
|
|
|
|
Assert.AreEqual(textPage.Key, updatedPickerValue.Key);
|
|
|
|
|
|
Assert.AreEqual(textPage.Id, updatedPickerValue.Id);
|
|
|
|
|
|
Assert.AreEqual(textPage.Name, updatedPickerValue.Name);
|
|
|
|
|
|
Assert.AreEqual("Updated title", updatedPickerValue.Properties.First(x => x.Alias == "title").GetValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private async Task<IContent> CreateContentPickerDocument(Guid templateKey, Guid textPageKey)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
var builder = new ContentTypeEditingBuilder();
|
|
|
|
|
|
var pickerContentType = builder
|
2024-09-10 00:49:18 +09:00
|
|
|
|
.WithAlias("test")
|
|
|
|
|
|
.WithName("TestName")
|
2024-09-24 09:39:23 +02:00
|
|
|
|
.WithAllowAtRoot(true)
|
|
|
|
|
|
.AddAllowedTemplateKeys([templateKey])
|
2024-09-10 00:49:18 +09:00
|
|
|
|
.AddPropertyGroup()
|
2024-09-24 09:39:23 +02:00
|
|
|
|
.WithName("Content")
|
|
|
|
|
|
.Done()
|
2024-09-10 00:49:18 +09:00
|
|
|
|
.AddPropertyType()
|
2024-09-24 09:39:23 +02:00
|
|
|
|
.WithAlias("contentPicker")
|
|
|
|
|
|
.WithName("Content Picker")
|
|
|
|
|
|
.WithDataTypeKey(Constants.DataTypes.Guids.ContentPickerGuid)
|
|
|
|
|
|
.WithSortOrder(16)
|
|
|
|
|
|
.Done()
|
2024-09-10 00:49:18 +09:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
await ContentTypeEditingService.CreateAsync(pickerContentType, Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var createOtherModel = new ContentCreateModel
|
|
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
ContentTypeKey = pickerContentType.Key.Value,
|
2024-09-10 00:49:18 +09:00
|
|
|
|
ParentKey = Constants.System.RootKey,
|
|
|
|
|
|
InvariantName = "Test Create",
|
|
|
|
|
|
InvariantProperties = new[] { new PropertyValueModel { Alias = "contentPicker", Value = textPageKey }, },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var result = await ContentEditingService.CreateAsync(createOtherModel, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(result.Success);
|
|
|
|
|
|
Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status);
|
|
|
|
|
|
|
|
|
|
|
|
var publishResult = await ContentPublishingService.PublishAsync(
|
|
|
|
|
|
result.Result.Content!.Key,
|
|
|
|
|
|
new CultureAndScheduleModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
CulturesToPublishImmediately = new HashSet<string> {"*"},
|
|
|
|
|
|
Schedules = new ContentScheduleCollection(),
|
|
|
|
|
|
},
|
|
|
|
|
|
Constants.Security.SuperUserKey);
|
|
|
|
|
|
|
|
|
|
|
|
return result.Result.Content;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-24 09:39:23 +02:00
|
|
|
|
private async Task<IContent> CreateTextPageDocument(Guid templateKey)
|
2024-09-10 00:49:18 +09:00
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
var textContentType = ContentTypeEditingBuilder.CreateTextPageContentType(defaultTemplateKey: templateKey);
|
|
|
|
|
|
await ContentTypeEditingService.CreateAsync(textContentType, Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
|
|
var createModel = new ContentCreateModel
|
|
|
|
|
|
{
|
2024-09-24 09:39:23 +02:00
|
|
|
|
ContentTypeKey = textContentType.Key.Value,
|
2024-09-10 00:49:18 +09:00
|
|
|
|
ParentKey = Constants.System.RootKey,
|
|
|
|
|
|
InvariantName = "Root Create",
|
|
|
|
|
|
InvariantProperties = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new PropertyValueModel { Alias = "title", Value = "The title value" },
|
|
|
|
|
|
new PropertyValueModel { Alias = "bodyText", Value = "The body text" }
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var createResult = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
|
|
|
|
|
Assert.IsTrue(createResult.Success);
|
|
|
|
|
|
|
|
|
|
|
|
var publishResult = await ContentPublishingService.PublishAsync(
|
|
|
|
|
|
createResult.Result.Content!.Key,
|
|
|
|
|
|
new CultureAndScheduleModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
CulturesToPublishImmediately = new HashSet<string> {"*"},
|
|
|
|
|
|
Schedules = new ContentScheduleCollection(),
|
|
|
|
|
|
},
|
|
|
|
|
|
Constants.Security.SuperUserKey);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(publishResult.Success);
|
|
|
|
|
|
return createResult.Result.Content;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|