* Block level variance - initial commit * Remove TODOs * Only convert RTEs with blocks * Fix JSON paths for block level property validation * Rename Properties to Values * Correct the JSON path of block level validation errors * Make it possible to skip content migration + ensure backwards compat for the new block format * Partial culture variance publishing at property level * UDI to key conversion for block editors - draft, WIP, do NOT merge 😄 (#16970) * Convert block UDIs to GUIDs * Fix merge * Fix merge issues * Rework nested layout item key parsing for backwards compatibility * Clean-up * Reverse block layout item key calculation * Review * Use IOptions to skip content migrations * Remove "published" from data editor feature naming, as it can be used in other contexts too * Parallel migration * Don't use deprecated constructor * Ensure that layout follows structure for partial publishing * Block Grid element level variance + tests (incl. refactor of element level variation tests) * Rollback unintended changes to Program.cs * Fix bad casing * Minor formatting * RTE element level variance + tests * Remove obsoleted constructors * Use Umbraco.RichText instead of Umbraco.TinyMCE as layout alias for blocks in the RTE * Fix bad merge * Temporary fix for new cache in integration tests * Add EditorAlias to block level properties * Remove the unintended PropertyEditorAlias output for block values * Add EditorAlias to Datatype Item model * Update OpenApi.json * Introduce "expose" for blocks * Strict (explicit) handling for Expose * Improve handling of document and element level variance changes * Refactor variance alignment for published rendering * Block UDI to Key conversion should also register as a conversion * Convert newly added RTE unit test to new RTE blocks format * Minor review changes * Run memory intensive tests on Linux only * Add tests proving that AllowEditInvariantFromNonDefault has effect for block level variance too * Fix the Platform annotations * Removed Platform annotations for tests. * Fix merge * Obsolete old PublishCulture extension * More fixing bad merge --------- Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com> Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch>
184 lines
9.6 KiB
C#
184 lines
9.6 KiB
C#
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Models.Blocks;
|
|
using Umbraco.Cms.Core.PropertyEditors;
|
|
using Umbraco.Cms.Core.Serialization;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.PropertyEditors;
|
|
|
|
[TestFixture]
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
public class RichTextPropertyEditorTests : UmbracoIntegrationTest
|
|
{
|
|
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
|
|
|
private IContentService ContentService => GetRequiredService<IContentService>();
|
|
|
|
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
|
|
|
|
private IJsonSerializer JsonSerializer => GetRequiredService<IJsonSerializer>();
|
|
|
|
[Test]
|
|
public void Can_Use_Markup_String_As_Value()
|
|
{
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType("myContentType");
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>();
|
|
ContentTypeService.Save(contentType);
|
|
|
|
var dataType = DataTypeService.GetDataType(contentType.PropertyTypes.First(propertyType => propertyType.Alias == "bodyText").DataTypeId)!;
|
|
var editor = dataType.Editor!;
|
|
var valueEditor = editor.GetValueEditor();
|
|
|
|
const string markup = "<p>This is some markup</p>";
|
|
|
|
var content = ContentBuilder.CreateTextpageContent(contentType, "My Content", -1);
|
|
content.Properties["bodyText"]!.SetValue(markup);
|
|
ContentService.Save(content);
|
|
|
|
var toEditor = valueEditor.ToEditor(content.Properties["bodyText"]);
|
|
var richTextEditorValue = toEditor as RichTextEditorValue;
|
|
|
|
Assert.IsNotNull(richTextEditorValue);
|
|
Assert.AreEqual(markup, richTextEditorValue.Markup);
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Use_RichTextEditorValue_As_Value()
|
|
{
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType("myContentType");
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>();
|
|
ContentTypeService.Save(contentType);
|
|
|
|
var dataType = DataTypeService.GetDataType(contentType.PropertyTypes.First(propertyType => propertyType.Alias == "bodyText").DataTypeId)!;
|
|
var editor = dataType.Editor!;
|
|
var valueEditor = editor.GetValueEditor();
|
|
|
|
const string markup = "<p>This is some markup</p>";
|
|
var propertyValue = RichTextPropertyEditorHelper.SerializeRichTextEditorValue(new RichTextEditorValue { Markup = markup, Blocks = null }, JsonSerializer);
|
|
|
|
var content = ContentBuilder.CreateTextpageContent(contentType, "My Content", -1);
|
|
content.Properties["bodyText"]!.SetValue(propertyValue);
|
|
ContentService.Save(content);
|
|
|
|
var toEditor = valueEditor.ToEditor(content.Properties["bodyText"]);
|
|
var richTextEditorValue = toEditor as RichTextEditorValue;
|
|
|
|
Assert.IsNotNull(richTextEditorValue);
|
|
Assert.AreEqual(markup, richTextEditorValue.Markup);
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Track_Block_References()
|
|
{
|
|
var elementType = ContentTypeBuilder.CreateAllTypesContentType("myElementType", "My Element Type");
|
|
elementType.IsElement = true;
|
|
ContentTypeService.Save(elementType);
|
|
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType("myContentType");
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>();
|
|
ContentTypeService.Save(contentType);
|
|
|
|
var pickedContent = ContentBuilder.CreateTextpageContent(contentType, "My Content", -1);
|
|
ContentService.Save(pickedContent);
|
|
|
|
var dataType = DataTypeService.GetDataType(contentType.PropertyTypes.First(propertyType => propertyType.Alias == "bodyText").DataTypeId)!;
|
|
var editor = dataType.Editor!;
|
|
var valueEditor = (BlockValuePropertyValueEditorBase<RichTextBlockValue, RichTextBlockLayoutItem>)editor.GetValueEditor();
|
|
|
|
var elementId = Guid.NewGuid();
|
|
var propertyValue = RichTextPropertyEditorHelper.SerializeRichTextEditorValue(
|
|
new RichTextEditorValue
|
|
{
|
|
Markup = @$"<p>This is some markup</p><umb-rte-block data-content-key=""{elementId:D}""><!--Umbraco-Block--></umb-rte-block>",
|
|
Blocks = JsonSerializer.Deserialize<RichTextBlockValue>($$"""
|
|
{
|
|
"layout": {
|
|
"Umbraco.TinyMCE": [{
|
|
"contentKey": "{{elementId:D}}"
|
|
}
|
|
]
|
|
},
|
|
"contentData": [{
|
|
"contentTypeKey": "{{elementType.Key:D}}",
|
|
"key": "{{elementId:D}}",
|
|
"values": [
|
|
{ "alias": "contentPicker", "value": "umb://document/{{pickedContent.Key:N}}" }
|
|
]
|
|
}
|
|
],
|
|
"settingsData": []
|
|
}
|
|
""")
|
|
},
|
|
JsonSerializer);
|
|
|
|
var content = ContentBuilder.CreateTextpageContent(contentType, "My Content", -1);
|
|
content.Properties["bodyText"]!.SetValue(propertyValue);
|
|
ContentService.Save(content);
|
|
|
|
var references = valueEditor.GetReferences(content.GetValue("bodyText")).ToArray();
|
|
Assert.AreEqual(1, references.Length);
|
|
var reference = references.First();
|
|
Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, reference.RelationTypeAlias);
|
|
Assert.AreEqual(pickedContent.GetUdi(), reference.Udi);
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Track_Block_Tags()
|
|
{
|
|
var elementType = ContentTypeBuilder.CreateAllTypesContentType("myElementType", "My Element Type");
|
|
elementType.IsElement = true;
|
|
ContentTypeService.Save(elementType);
|
|
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType("myContentType");
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>();
|
|
ContentTypeService.Save(contentType);
|
|
|
|
var dataType = DataTypeService.GetDataType(contentType.PropertyTypes.First(propertyType => propertyType.Alias == "bodyText").DataTypeId)!;
|
|
var editor = dataType.Editor!;
|
|
var valueEditor = (BlockValuePropertyValueEditorBase<RichTextBlockValue, RichTextBlockLayoutItem>)editor.GetValueEditor();
|
|
|
|
var elementId = Guid.NewGuid();
|
|
var propertyValue = RichTextPropertyEditorHelper.SerializeRichTextEditorValue(
|
|
new RichTextEditorValue
|
|
{
|
|
Markup = @$"<p>This is some markup</p><umb-rte-block data-content-key=""{elementId:D}""><!--Umbraco-Block--></umb-rte-block>",
|
|
Blocks = JsonSerializer.Deserialize<RichTextBlockValue>($$"""
|
|
{
|
|
"layout": {
|
|
"Umbraco.TinyMCE": [{
|
|
"contentKey": "{{elementId:D}}"
|
|
}
|
|
]
|
|
},
|
|
"contentData": [{
|
|
"contentTypeKey": "{{elementType.Key:D}}",
|
|
"key": "{{elementId:D}}",
|
|
"values": [
|
|
{ "alias": "tags", "value": "[\"Tag One\", \"Tag Two\", \"Tag Three\"]" }
|
|
]
|
|
}
|
|
],
|
|
"settingsData": []
|
|
}
|
|
""")
|
|
},
|
|
JsonSerializer);
|
|
|
|
var content = ContentBuilder.CreateTextpageContent(contentType, "My Content", -1);
|
|
content.Properties["bodyText"]!.SetValue(propertyValue);
|
|
ContentService.Save(content);
|
|
|
|
var tags = valueEditor.GetTags(content.GetValue("bodyText"), null, null).ToArray();
|
|
Assert.AreEqual(3, tags.Length);
|
|
Assert.IsNotNull(tags.Single(tag => tag.Text == "Tag One"));
|
|
Assert.IsNotNull(tags.Single(tag => tag.Text == "Tag Two"));
|
|
Assert.IsNotNull(tags.Single(tag => tag.Text == "Tag Three"));
|
|
}
|
|
}
|