Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/PropertyEditors/BlockEditorBackwardsCompatibilityTests.cs

415 lines
19 KiB
C#
Raw Permalink Normal View History

Remove the non-controversial, straightforward obsoleted constructs for Umbraco 16 (#18661) * Removed obsoletes from IConfigManipulator. * Removed obsolete models builder extensions. * Removed the obsolete ContentDashboardSettings. * Removed the obsolete InstallMissingDatabase setting on GlobalSettings. * Removed obsolete NuCache settings. * Removed obsolete RuntimeMinificationSettings. * Removed obsolete health check constant. * Removed obsolete icon constant. * Removed obsolete telemetry constant. * Removed obsolete property and constructor on UmbracoBuilder. * Removed obsolete constructor on AuditNotificationsHandler. * Removed obsolete constructor on HTTP header health checks. * Removed obsolete constructor on MediaFileManager. * Removed obsolete GetDefaultFileContent on ViewHelper. * Remove obsoleted methods on embed providers. * Fix tests. * Removed obsolete constructors on BlockEditorDataConverter. * Removed obsolete SeedCacheDuration property on CacheSettings. * Removed obsolete PublishCulture on ContentRepositoryExtensions. * Removed obsolete MonitorLock. * Removed obsolete synchronous HasSavedValues from IDataTypeUsageService and IDataTypeUsageRepository. * Removed obsolete HasSavedPropertyValues from IPropertyTypeUsageService and IPropertyTypeUsageRepository. * Removed obsolete methods in ITrackedReferencesService and ITrackedReferencesRepository. * Removed obsolete DateValueEditor constructors. * Removed obsolete GetAutomaticRelationTypesAliases. * Removed obsolete constructor on TextOnlyValueEditor. * Removed obsolete constructors on RegexValidator and RequiredValidator. * Removed obsolete constructs on SliderValueConverter and TagsValueConverter. * Removed obsolete GetContentType methods from IPublishedCache. * Removed ContentFinderByIdPath. * Removed obsolete constructor on DefaultMediaUrlProvider. * Removed obsolete constructor on Domain. * Removed obsolete constructor on PublishedRequest. * Removed obsolete methods on CheckPermissions. * Removed obsolete GetUserId from IBackOfficeSecurity. * Removed obsolete methods on LegacyPasswordSecurity. * Removed obsolete constructors on AuditService. * Removed obsolete methods on IContentEditingService. * Remove obsolete constructors and methods on ContentService/IContentService. * Removed obsolete constructor in ContentTypeEditingService. * Removed obsolete constructor in MediaTypeEditingService. * Removed obsolete constructor in MemberTypeEditingService. * Removed obsolete constructor in ContentTypeService. * Removed obsolete constructors in ContentTypeServiceBase. * Removed obsolete constructors and methods in ContentVersionService. * Removed obsolete constructor in DataTypeUsageService. * Removed obsolete constructor in DomainService. * Removed obsolete constructor in FileService. * Removes obsolete AttemptMove from IContentService. * Removes obsolete SetPreventCleanup from IContentVersionService. * Removes obsolete GetReferences from IDataTypeService. * Removed obsolete SetConsentLevel from IMetricsConsentService. * Removed obsolete methods from IPackageDataInstallation. * Removed obsolete methods from IPackagingService. * Removed obsolete methods on ITwoFactorLoginService. Removed obsolete ITemporaryMediaService. * Removed obsolete constructor from MediaService, MemberTypeService and MediaTypeService. * More obsolete constructors. * Removed obsoleted overloads on IPropertyValidationService. * Fixed build for tests. * Removed obsolete constructor for PublicAccessService, UserService and RelationService. * Removed GetDefaultMemberType. * Removed obsolete user group functionality from IUserService. * Removed obsolete extension methods on IUserService. * Removed obsolete method from ITelemetryService. * Removed obsolete UdiParserServiceConnectors. * Removed obsolete method on ICookieManager. * Removed obsolete DynamicContext. * Removed obsolete XmlHelper. * Fixed failing integration tests. * Removed obsoletes in Umbraco.Cms.Api.Common * Removed obsoletes in Umbraco.Cms.Api.Delivery * Removed obsoletes in Umbraco.Cms.Api.Management * Removed obsoletes in Umbraco.Examine.Lucene * Removed obsoletes in Umbraco.Infrastructure * Fix failing delivery API contract integration test. * Made integration tests internal. * Removed obsoletes from web projects. * Fix build. * Removed Twitter OEmbed provider * Removed obsolete constructor on PublishedDataType. * Removed obsolete constructors on PublishedCacheBase. * Removed the obsolete PropertyEditorTagsExtensions. * Removed obsoletion properties on configuration response models (#18697) * Removed obsolete methods from server-side models. * Update client-side types and sdk. * Update client-side files. * Removed obsoletion of Utf8ToAsciiConverter.ToAsciiString overload. (#18694) * Removed obsolete method in UserService. (#18710) * Removed obsoleted group alias keys from being publicly available. (#18682) * Removed unneceessary ApiVersion attribute. * Clean-up obsoletions on MemberService (#18703) * Removed obsoleted method on MemberService, added future obsoletion to interface and updated all callers. * Removed obsoletion on member service method that's not obsolete on the interface.
2025-03-21 18:02:31 +01:00
using NUnit.Framework;
Block level variance (#17120) * 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>
2024-09-30 07:01:18 +02:00
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.Builders.Extensions;
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)]
Remove the non-controversial, straightforward obsoleted constructs for Umbraco 16 (#18661) * Removed obsoletes from IConfigManipulator. * Removed obsolete models builder extensions. * Removed the obsolete ContentDashboardSettings. * Removed the obsolete InstallMissingDatabase setting on GlobalSettings. * Removed obsolete NuCache settings. * Removed obsolete RuntimeMinificationSettings. * Removed obsolete health check constant. * Removed obsolete icon constant. * Removed obsolete telemetry constant. * Removed obsolete property and constructor on UmbracoBuilder. * Removed obsolete constructor on AuditNotificationsHandler. * Removed obsolete constructor on HTTP header health checks. * Removed obsolete constructor on MediaFileManager. * Removed obsolete GetDefaultFileContent on ViewHelper. * Remove obsoleted methods on embed providers. * Fix tests. * Removed obsolete constructors on BlockEditorDataConverter. * Removed obsolete SeedCacheDuration property on CacheSettings. * Removed obsolete PublishCulture on ContentRepositoryExtensions. * Removed obsolete MonitorLock. * Removed obsolete synchronous HasSavedValues from IDataTypeUsageService and IDataTypeUsageRepository. * Removed obsolete HasSavedPropertyValues from IPropertyTypeUsageService and IPropertyTypeUsageRepository. * Removed obsolete methods in ITrackedReferencesService and ITrackedReferencesRepository. * Removed obsolete DateValueEditor constructors. * Removed obsolete GetAutomaticRelationTypesAliases. * Removed obsolete constructor on TextOnlyValueEditor. * Removed obsolete constructors on RegexValidator and RequiredValidator. * Removed obsolete constructs on SliderValueConverter and TagsValueConverter. * Removed obsolete GetContentType methods from IPublishedCache. * Removed ContentFinderByIdPath. * Removed obsolete constructor on DefaultMediaUrlProvider. * Removed obsolete constructor on Domain. * Removed obsolete constructor on PublishedRequest. * Removed obsolete methods on CheckPermissions. * Removed obsolete GetUserId from IBackOfficeSecurity. * Removed obsolete methods on LegacyPasswordSecurity. * Removed obsolete constructors on AuditService. * Removed obsolete methods on IContentEditingService. * Remove obsolete constructors and methods on ContentService/IContentService. * Removed obsolete constructor in ContentTypeEditingService. * Removed obsolete constructor in MediaTypeEditingService. * Removed obsolete constructor in MemberTypeEditingService. * Removed obsolete constructor in ContentTypeService. * Removed obsolete constructors in ContentTypeServiceBase. * Removed obsolete constructors and methods in ContentVersionService. * Removed obsolete constructor in DataTypeUsageService. * Removed obsolete constructor in DomainService. * Removed obsolete constructor in FileService. * Removes obsolete AttemptMove from IContentService. * Removes obsolete SetPreventCleanup from IContentVersionService. * Removes obsolete GetReferences from IDataTypeService. * Removed obsolete SetConsentLevel from IMetricsConsentService. * Removed obsolete methods from IPackageDataInstallation. * Removed obsolete methods from IPackagingService. * Removed obsolete methods on ITwoFactorLoginService. Removed obsolete ITemporaryMediaService. * Removed obsolete constructor from MediaService, MemberTypeService and MediaTypeService. * More obsolete constructors. * Removed obsoleted overloads on IPropertyValidationService. * Fixed build for tests. * Removed obsolete constructor for PublicAccessService, UserService and RelationService. * Removed GetDefaultMemberType. * Removed obsolete user group functionality from IUserService. * Removed obsolete extension methods on IUserService. * Removed obsolete method from ITelemetryService. * Removed obsolete UdiParserServiceConnectors. * Removed obsolete method on ICookieManager. * Removed obsolete DynamicContext. * Removed obsolete XmlHelper. * Fixed failing integration tests. * Removed obsoletes in Umbraco.Cms.Api.Common * Removed obsoletes in Umbraco.Cms.Api.Delivery * Removed obsoletes in Umbraco.Cms.Api.Management * Removed obsoletes in Umbraco.Examine.Lucene * Removed obsoletes in Umbraco.Infrastructure * Fix failing delivery API contract integration test. * Made integration tests internal. * Removed obsoletes from web projects. * Fix build. * Removed Twitter OEmbed provider * Removed obsolete constructor on PublishedDataType. * Removed obsolete constructors on PublishedCacheBase. * Removed the obsolete PropertyEditorTagsExtensions. * Removed obsoletion properties on configuration response models (#18697) * Removed obsolete methods from server-side models. * Update client-side types and sdk. * Update client-side files. * Removed obsoletion of Utf8ToAsciiConverter.ToAsciiString overload. (#18694) * Removed obsolete method in UserService. (#18710) * Removed obsoleted group alias keys from being publicly available. (#18682) * Removed unneceessary ApiVersion attribute. * Clean-up obsoletions on MemberService (#18703) * Removed obsoleted method on MemberService, added future obsoletion to interface and updated all callers. * Removed obsoletion on member service method that's not obsolete on the interface.
2025-03-21 18:02:31 +01:00
internal sealed class BlockEditorBackwardsCompatibilityTests : UmbracoIntegrationTest
Block level variance (#17120) * 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>
2024-09-30 07:01:18 +02:00
{
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IContentService ContentService => GetRequiredService<IContentService>();
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
private PropertyEditorCollection PropertyEditorCollection => GetRequiredService<PropertyEditorCollection>();
private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer => GetRequiredService<IConfigurationEditorJsonSerializer>();
[TestCase]
public async Task BlockListIsBackwardsCompatible()
{
var elementType = await CreateElementType();
var blockListDataType = await CreateBlockListDataType(elementType);
var contentType = await CreateContentType(blockListDataType);
var json = $$"""
{
"layout": {
"{{Constants.PropertyEditors.Aliases.BlockList}}": [
{
"contentUdi": "umb://element/1304e1ddac87439684fe8a399231cb3d",
"settingsUdi": "umb://element/1f613e26ce274898908a561437af5100"
},
{
"contentUdi": "umb://element/0a4a416e547d464fabcc6f345c17809a",
"settingsUdi": "umb://element/63027539b0db45e7b70459762d4e83dd"
}
]
},
"contentData": [
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/1304e1ddac87439684fe8a399231cb3d",
"title": "Content Title One",
"text": "Content Text One"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/0a4a416e547d464fabcc6f345c17809a",
"title": "Content Title Two",
"text": "Content Text Two"
}
],
"settingsData": [
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/1f613e26ce274898908a561437af5100",
"title": "Settings Title One",
"text": "Settings Text One"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/63027539b0db45e7b70459762d4e83dd",
"title": "Settings Title Two",
"text": "Settings Text Two"
}
]
}
""";
var contentBuilder = new ContentBuilder()
.WithContentType(contentType)
.WithName("Home");
var content = contentBuilder.Build();
content.Properties["blocks"]!.SetValue(json);
ContentService.Save(content);
var toEditor = blockListDataType.Editor!.GetValueEditor().ToEditor(content.Properties["blocks"]!) as BlockListValue;
Assert.IsNotNull(toEditor);
Assert.Multiple(() =>
{
Assert.AreEqual(2, toEditor.ContentData.Count);
Assert.AreEqual("1304e1ddac87439684fe8a399231cb3d", toEditor.ContentData[0].Key.ToString("N"));
Assert.AreEqual("0a4a416e547d464fabcc6f345c17809a", toEditor.ContentData[1].Key.ToString("N"));
AssertValueEquals(toEditor.ContentData[0], "title", "Content Title One");
AssertValueEquals(toEditor.ContentData[0], "text", "Content Text One");
AssertValueEquals(toEditor.ContentData[1], "title", "Content Title Two");
AssertValueEquals(toEditor.ContentData[1], "text", "Content Text Two");
Assert.IsFalse(toEditor.ContentData[0].RawPropertyValues.Any());
Assert.IsFalse(toEditor.ContentData[1].RawPropertyValues.Any());
});
Assert.Multiple(() =>
{
Assert.AreEqual(2, toEditor.SettingsData.Count);
Assert.AreEqual("1f613e26ce274898908a561437af5100", toEditor.SettingsData[0].Key.ToString("N"));
Assert.AreEqual("63027539b0db45e7b70459762d4e83dd", toEditor.SettingsData[1].Key.ToString("N"));
AssertValueEquals(toEditor.SettingsData[0], "title", "Settings Title One");
AssertValueEquals(toEditor.SettingsData[0], "text", "Settings Text One");
AssertValueEquals(toEditor.SettingsData[1], "title", "Settings Title Two");
AssertValueEquals(toEditor.SettingsData[1], "text", "Settings Text Two");
Assert.IsFalse(toEditor.SettingsData[0].RawPropertyValues.Any());
Assert.IsFalse(toEditor.SettingsData[1].RawPropertyValues.Any());
});
Assert.Multiple(() =>
{
Assert.AreEqual(2, toEditor.Expose.Count);
Assert.AreEqual("1304e1ddac87439684fe8a399231cb3d", toEditor.Expose[0].ContentKey.ToString("N"));
Assert.AreEqual("0a4a416e547d464fabcc6f345c17809a", toEditor.Expose[1].ContentKey.ToString("N"));
});
}
[TestCase]
public async Task BlockGridIsBackwardsCompatible()
{
var elementType = await CreateElementType();
var gridAreaKey = Guid.NewGuid();
var blockGridDataType = await CreateBlockGridDataType(elementType, gridAreaKey);
var contentType = await CreateContentType(blockGridDataType);
var json = $$"""
{
"layout": {
"{{Constants.PropertyEditors.Aliases.BlockGrid}}": [
{
"contentUdi": "umb://element/1304e1ddac87439684fe8a399231cb3d",
"settingsUdi": "umb://element/1f613e26ce274898908a561437af5100",
"columnSpan": 12,
"rowSpan": 1,
"areas": [{
"key": "{{gridAreaKey}}",
"items": [{
"contentUdi": "umb://element/5fc866c590be4d01a28a979472a1ffee",
"areas": [],
"columnSpan": 12,
"rowSpan": 1
}]
}]
},
{
"contentUdi": "umb://element/0a4a416e547d464fabcc6f345c17809a",
"settingsUdi": "umb://element/63027539b0db45e7b70459762d4e83dd",
"columnSpan": 12,
"rowSpan": 1,
"areas": [{
"key": "{{gridAreaKey}}",
"items": [{
"contentUdi": "umb://element/264536b65b0f4641aa43d4bfb515831d",
"areas": [],
"columnSpan": 12,
"rowSpan": 1
}]
}]
}
]
},
"contentData": [
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/1304e1ddac87439684fe8a399231cb3d",
"title": "Content Title One",
"text": "Content Text One"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/0a4a416e547d464fabcc6f345c17809a",
"title": "Content Title Two",
"text": "Content Text Two"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/5fc866c590be4d01a28a979472a1ffee",
"title": "Content Area Title One",
"text": "Content Area Text One"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/264536b65b0f4641aa43d4bfb515831d",
"title": "Content Area Title Two",
"text": "Content Area Text Two"
}
],
"settingsData": [
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/1f613e26ce274898908a561437af5100",
"title": "Settings Title One",
"text": "Settings Text One"
},
{
"contentTypeKey": "{{elementType.Key}}",
"udi": "umb://element/63027539b0db45e7b70459762d4e83dd",
"title": "Settings Title Two",
"text": "Settings Text Two"
}
]
}
""";
var contentBuilder = new ContentBuilder()
.WithContentType(contentType)
.WithName("Home");
var content = contentBuilder.Build();
content.Properties["blocks"]!.SetValue(json);
ContentService.Save(content);
var toEditor = blockGridDataType.Editor!.GetValueEditor().ToEditor(content.Properties["blocks"]!) as BlockGridValue;
Assert.IsNotNull(toEditor);
Assert.AreEqual(4, toEditor.ContentData.Count);
Assert.Multiple(() =>
{
Assert.AreEqual("1304e1ddac87439684fe8a399231cb3d", toEditor.ContentData[0].Key.ToString("N"));
Assert.AreEqual("0a4a416e547d464fabcc6f345c17809a", toEditor.ContentData[1].Key.ToString("N"));
Assert.AreEqual("5fc866c590be4d01a28a979472a1ffee", toEditor.ContentData[2].Key.ToString("N"));
Assert.AreEqual("264536b65b0f4641aa43d4bfb515831d", toEditor.ContentData[3].Key.ToString("N"));
AssertValueEquals(toEditor.ContentData[0], "title", "Content Title One");
AssertValueEquals(toEditor.ContentData[0], "text", "Content Text One");
AssertValueEquals(toEditor.ContentData[1], "title", "Content Title Two");
AssertValueEquals(toEditor.ContentData[1], "text", "Content Text Two");
AssertValueEquals(toEditor.ContentData[2], "title", "Content Area Title One");
AssertValueEquals(toEditor.ContentData[2], "text", "Content Area Text One");
AssertValueEquals(toEditor.ContentData[3], "title", "Content Area Title Two");
AssertValueEquals(toEditor.ContentData[3], "text", "Content Area Text Two");
Assert.IsFalse(toEditor.ContentData[0].RawPropertyValues.Any());
Assert.IsFalse(toEditor.ContentData[1].RawPropertyValues.Any());
Assert.IsFalse(toEditor.ContentData[2].RawPropertyValues.Any());
Assert.IsFalse(toEditor.ContentData[3].RawPropertyValues.Any());
});
Assert.AreEqual(2, toEditor.SettingsData.Count);
Assert.Multiple(() =>
{
Assert.AreEqual("1f613e26ce274898908a561437af5100", toEditor.SettingsData[0].Key.ToString("N"));
Assert.AreEqual("63027539b0db45e7b70459762d4e83dd", toEditor.SettingsData[1].Key.ToString("N"));
AssertValueEquals(toEditor.SettingsData[0], "title", "Settings Title One");
AssertValueEquals(toEditor.SettingsData[0], "text", "Settings Text One");
AssertValueEquals(toEditor.SettingsData[1], "title", "Settings Title Two");
AssertValueEquals(toEditor.SettingsData[1], "text", "Settings Text Two");
Assert.IsFalse(toEditor.SettingsData[0].RawPropertyValues.Any());
Assert.IsFalse(toEditor.SettingsData[1].RawPropertyValues.Any());
});
Assert.Multiple(() =>
{
Assert.AreEqual(4, toEditor.Expose.Count);
Assert.AreEqual("1304e1ddac87439684fe8a399231cb3d", toEditor.Expose[0].ContentKey.ToString("N"));
Assert.AreEqual("0a4a416e547d464fabcc6f345c17809a", toEditor.Expose[1].ContentKey.ToString("N"));
Assert.AreEqual("5fc866c590be4d01a28a979472a1ffee", toEditor.Expose[2].ContentKey.ToString("N"));
Assert.AreEqual("264536b65b0f4641aa43d4bfb515831d", toEditor.Expose[3].ContentKey.ToString("N"));
});
}
private static void AssertValueEquals(BlockItemData blockItemData, string propertyAlias, string expectedValue)
{
var blockPropertyValue = blockItemData.Values.FirstOrDefault(v => v.Alias == propertyAlias);
Assert.IsNotNull(blockPropertyValue);
Assert.AreEqual(expectedValue, blockPropertyValue.Value);
}
private async Task<IContentType> CreateElementType()
{
var elementType = new ContentTypeBuilder()
.WithAlias("myElementType")
.WithName("My Element Type")
.WithIsElement(true)
.AddPropertyType()
.WithAlias("title")
.WithName("Title")
.WithDataTypeId(Constants.DataTypes.Textbox)
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
.WithValueStorageType(ValueStorageType.Nvarchar)
.Done()
.AddPropertyType()
.WithAlias("text")
.WithName("Text")
.WithDataTypeId(Constants.DataTypes.Textbox)
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
.WithValueStorageType(ValueStorageType.Nvarchar)
.Done()
.Build();
await ContentTypeService.CreateAsync(elementType, Constants.Security.SuperUserKey);
return elementType;
}
private async Task<IDataType> CreateBlockListDataType(IContentType elementType)
{
var dataType = new DataType(PropertyEditorCollection[Constants.PropertyEditors.Aliases.BlockList], ConfigurationEditorJsonSerializer)
{
ConfigurationData = new Dictionary<string, object>
{
{
"blocks",
new BlockListConfiguration.BlockConfiguration[]
{
new() { ContentElementTypeKey = elementType.Key, SettingsElementTypeKey = elementType.Key }
}
}
},
Name = "My Block List",
DatabaseType = ValueStorageType.Ntext,
ParentId = Constants.System.Root,
CreateDate = DateTime.UtcNow
};
await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey);
return dataType;
}
private async Task<IDataType> CreateBlockGridDataType(IContentType elementType, Guid gridAreaKey)
{
var dataType = new DataType(PropertyEditorCollection[Constants.PropertyEditors.Aliases.BlockGrid], ConfigurationEditorJsonSerializer)
{
ConfigurationData = new Dictionary<string, object>
{
{
"blocks",
new BlockGridConfiguration.BlockGridBlockConfiguration[]
{
new()
{
ContentElementTypeKey = elementType.Key,
SettingsElementTypeKey = elementType.Key,
AllowInAreas = true,
AllowAtRoot = true,
Areas =
[
new BlockGridConfiguration.BlockGridAreaConfiguration
{
Key = gridAreaKey,
Alias = "areaOne"
}
]
}
}
}
},
Name = "My Block Grid",
DatabaseType = ValueStorageType.Ntext,
ParentId = Constants.System.Root,
CreateDate = DateTime.UtcNow
};
await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey);
return dataType;
}
private async Task<IDataType> CreateRichTextDataType(IContentType elementType)
{
var dataType = new DataType(PropertyEditorCollection[Constants.PropertyEditors.Aliases.RichText], ConfigurationEditorJsonSerializer)
{
ConfigurationData = new Dictionary<string, object>
{
{
"blocks",
new RichTextConfiguration.RichTextBlockConfiguration[]
{
new() { ContentElementTypeKey = elementType.Key, SettingsElementTypeKey = elementType.Key }
}
}
},
Name = "My Rich Text",
DatabaseType = ValueStorageType.Ntext,
ParentId = Constants.System.Root,
CreateDate = DateTime.UtcNow
};
await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey);
return dataType;
}
private async Task<IContentType> CreateContentType(IDataType blockEditorDataType)
{
var contentType = new ContentTypeBuilder()
.WithAlias("myPage")
.WithName("My Page")
.AddPropertyType()
.WithAlias("blocks")
.WithName("Blocks")
.WithDataTypeId(blockEditorDataType.Id)
.Done()
.Build();
await ContentTypeService.CreateAsync(contentType, Constants.Security.SuperUserKey);
return contentType;
}
}