Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PropertyEditors/BlockEditorVarianceHandlerTests.cs
Kenn Jacobsen 1be503e71f 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

76 lines
3.0 KiB
C#

using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.PropertyEditors;
// TODO KJA: more tests for BlockEditorVarianceHandler
[TestFixture]
public class BlockEditorVarianceHandlerTests
{
[Test]
public async Task Assigns_Default_Culture_When_Culture_Variance_Is_Enabled()
{
var propertyValue = new BlockPropertyValue { Culture = null };
var subject = BlockEditorVarianceHandler("da-DK");
var result = await subject.AlignedPropertyVarianceAsync(
propertyValue,
PublishedPropertyType(ContentVariation.Culture),
PublishedElement(ContentVariation.Culture));
Assert.IsNotNull(result);
Assert.AreEqual("da-DK", result.Culture);
}
[Test]
public async Task Removes_Default_Culture_When_Culture_Variance_Is_Disabled()
{
var propertyValue = new BlockPropertyValue { Culture = "da-DK" };
var subject = BlockEditorVarianceHandler("da-DK");
var result = await subject.AlignedPropertyVarianceAsync(
propertyValue,
PublishedPropertyType(ContentVariation.Nothing),
PublishedElement(ContentVariation.Nothing));
Assert.IsNotNull(result);
Assert.AreEqual(null, result.Culture);
}
[Test]
public async Task Ignores_NonDefault_Culture_When_Culture_Variance_Is_Disabled()
{
var propertyValue = new BlockPropertyValue { Culture = "en-US" };
var subject = BlockEditorVarianceHandler("da-DK");
var result = await subject.AlignedPropertyVarianceAsync(
propertyValue,
PublishedPropertyType(ContentVariation.Nothing),
PublishedElement(ContentVariation.Nothing));
Assert.IsNull(result);
}
private static IPublishedPropertyType PublishedPropertyType(ContentVariation variation)
{
var propertyTypeMock = new Mock<IPublishedPropertyType>();
propertyTypeMock.SetupGet(m => m.Variations).Returns(variation);
return propertyTypeMock.Object;
}
private static IPublishedElement PublishedElement(ContentVariation variation)
{
var contentTypeMock = new Mock<IPublishedContentType>();
contentTypeMock.SetupGet(m => m.Variations).Returns(variation);
var elementMock = new Mock<IPublishedElement>();
elementMock.SetupGet(m => m.ContentType).Returns(contentTypeMock.Object);
return elementMock.Object;
}
private static BlockEditorVarianceHandler BlockEditorVarianceHandler(string defaultLanguageIsoCode)
{
var languageServiceMock = new Mock<ILanguageService>();
languageServiceMock.Setup(m => m.GetDefaultIsoCodeAsync()).ReturnsAsync(defaultLanguageIsoCode);
return new BlockEditorVarianceHandler(languageServiceMock.Object);
}
}