diff --git a/src/Mapper/BaseMapper.php b/src/Mapper/BaseMapper.php index 4a919389..0b3d36fe 100644 --- a/src/Mapper/BaseMapper.php +++ b/src/Mapper/BaseMapper.php @@ -13,6 +13,8 @@ use Contentful\Core\ResourceBuilder\MapperInterface; use Contentful\Core\ResourceBuilder\ObjectHydrator; +use Contentful\Management\Resource\ContentType\Validation\AbstractCustomMessageValidation; +use Contentful\Management\Resource\ContentType\Validation\ValidationInterface; use Contentful\Management\ResourceBuilder; /** @@ -38,4 +40,29 @@ public function __construct(ResourceBuilder $builder) $this->builder = $builder; $this->hydrator = new ObjectHydrator(); } + + protected function mapValidation(array $data): ?ValidationInterface + { + $message = null; + if (isset($data['message'])) { + $message = $data['message']; + unset($data['message']); + } + + if (empty(array_values($data)[0])) { + return null; + } + + $fqcn = '\\Contentful\\Management\\Mapper\\ContentType\\Validation\\'.\ucfirst(key($data)).'Validation'; + + /** @var ValidationInterface $validation */ + $validation = $this->builder->getMapper($fqcn) + ->map(null, $data); + + if ($validation instanceof AbstractCustomMessageValidation && $message) { + $validation->setMessage($message); + } + + return $validation; + } } diff --git a/src/Mapper/ContentType/Field/BaseField.php b/src/Mapper/ContentType/Field/BaseField.php index 0bf7ce8f..6e19e017 100644 --- a/src/Mapper/ContentType/Field/BaseField.php +++ b/src/Mapper/ContentType/Field/BaseField.php @@ -22,7 +22,6 @@ use Contentful\Management\Resource\ContentType\Field\RichTextField; use Contentful\Management\Resource\ContentType\Field\SymbolField; use Contentful\Management\Resource\ContentType\Field\TextField; -use Contentful\Management\Resource\ContentType\Validation\ValidationInterface; /** * BaseField class. @@ -56,22 +55,10 @@ public function map($resource, array $data): FieldInterface 'disabled' => $data['disabled'] ?? null, 'omitted' => $data['omitted'] ?? null, 'validations' => isset($data['validations']) - ? \array_map([$this, 'mapValidation'], $data['validations']) + ? \array_filter(\array_map([$this, 'mapValidation'], $data['validations'])) : [], ]); return $field; } - - protected function mapValidation(array $data): ValidationInterface - { - $fqcn = '\\Contentful\\Management\\Mapper\\ContentType\\Validation\\'.\ucfirst(\array_keys($data)[0]).'Validation'; - - /** @var ValidationInterface $validation */ - $validation = $this->builder->getMapper($fqcn) - ->map(null, $data) - ; - - return $validation; - } } diff --git a/src/Mapper/ContentType/Validation/EnabledMarksValidation.php b/src/Mapper/ContentType/Validation/EnabledMarksValidation.php index d8cdcf58..46b8adc0 100644 --- a/src/Mapper/ContentType/Validation/EnabledMarksValidation.php +++ b/src/Mapper/ContentType/Validation/EnabledMarksValidation.php @@ -24,6 +24,6 @@ class EnabledMarksValidation extends BaseMapper */ public function map($resource, array $data): ResourceClass { - return new ResourceClass(); + return new ResourceClass($data['enabledMarks']); } } diff --git a/src/Mapper/ContentType/Validation/EnabledNodeTypesValidation.php b/src/Mapper/ContentType/Validation/EnabledNodeTypesValidation.php index a20077bb..6acd729d 100644 --- a/src/Mapper/ContentType/Validation/EnabledNodeTypesValidation.php +++ b/src/Mapper/ContentType/Validation/EnabledNodeTypesValidation.php @@ -24,6 +24,6 @@ class EnabledNodeTypesValidation extends BaseMapper */ public function map($resource, array $data): ResourceClass { - return new ResourceClass(); + return new ResourceClass($data['enabledNodeTypes']); } } diff --git a/src/Mapper/ContentType/Validation/NodesValidation.php b/src/Mapper/ContentType/Validation/NodesValidation.php index bcc0a9e0..235769c0 100644 --- a/src/Mapper/ContentType/Validation/NodesValidation.php +++ b/src/Mapper/ContentType/Validation/NodesValidation.php @@ -24,6 +24,22 @@ class NodesValidation extends BaseMapper */ public function map($resource, array $data): ResourceClass { - return new ResourceClass(); + return new ResourceClass( + isset($data['nodes']['asset-hyperlink']) ? + \array_map([$this, 'mapValidation'], $data['nodes']['asset-hyperlink']) : + [], + isset($data['nodes']['embedded-asset-block']) ? + \array_map([$this, 'mapValidation'], $data['nodes']['embedded-asset-block']) : + [], + isset($data['nodes']['embedded-entry-block']) ? + \array_map([$this, 'mapValidation'], $data['nodes']['embedded-entry-block']) : + [], + isset($data['nodes']['embedded-entry-inline']) ? + \array_map([$this, 'mapValidation'], $data['nodes']['embedded-entry-inline']) : + [], + isset($data['nodes']['entry-hyperlink']) ? + \array_map([$this, 'mapValidation'], $data['nodes']['entry-hyperlink']) : + [] + ); } } diff --git a/src/Resource/ContentType/Validation/AbstractCustomMessageValidation.php b/src/Resource/ContentType/Validation/AbstractCustomMessageValidation.php new file mode 100644 index 00000000..94c02db1 --- /dev/null +++ b/src/Resource/ContentType/Validation/AbstractCustomMessageValidation.php @@ -0,0 +1,29 @@ +message = $message; + + return $this; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function jsonSerialize(): array + { + return $this->message ? ['message' => $this->message] : []; + } +} diff --git a/src/Resource/ContentType/Validation/AssetFileSizeValidation.php b/src/Resource/ContentType/Validation/AssetFileSizeValidation.php index 9cf832dd..0292aa73 100644 --- a/src/Resource/ContentType/Validation/AssetFileSizeValidation.php +++ b/src/Resource/ContentType/Validation/AssetFileSizeValidation.php @@ -19,7 +19,7 @@ * Applicable to: * - Link (to assets) */ -class AssetFileSizeValidation implements ValidationInterface +class AssetFileSizeValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var int|null @@ -100,8 +100,9 @@ public function jsonSerialize(): array $data['max'] = $this->max; } - return [ + return array_merge( + parent::jsonSerialize(), [ 'assetFileSize' => $data, - ]; + ]); } } diff --git a/src/Resource/ContentType/Validation/AssetImageDimensionsValidation.php b/src/Resource/ContentType/Validation/AssetImageDimensionsValidation.php index e7b3b66a..bbe7224b 100644 --- a/src/Resource/ContentType/Validation/AssetImageDimensionsValidation.php +++ b/src/Resource/ContentType/Validation/AssetImageDimensionsValidation.php @@ -19,7 +19,7 @@ * Applicable to: * - Link (to image assets) */ -class AssetImageDimensionsValidation implements ValidationInterface +class AssetImageDimensionsValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var int|null @@ -161,8 +161,11 @@ public function jsonSerialize(): array $data['height'] = $heightData; } - return [ - 'assetImageDimensions' => $data, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'assetImageDimensions' => $data, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/DateRangeValidation.php b/src/Resource/ContentType/Validation/DateRangeValidation.php index aebd7ee3..083de504 100644 --- a/src/Resource/ContentType/Validation/DateRangeValidation.php +++ b/src/Resource/ContentType/Validation/DateRangeValidation.php @@ -19,7 +19,7 @@ * Applicable to: * - Date */ -class DateRangeValidation implements ValidationInterface +class DateRangeValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var string|null @@ -97,8 +97,11 @@ public function jsonSerialize(): array $data['max'] = $this->max; } - return [ - 'dateRange' => $data, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'dateRange' => $data, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/EnabledMarksValidation.php b/src/Resource/ContentType/Validation/EnabledMarksValidation.php index 71fc8706..f2aae211 100644 --- a/src/Resource/ContentType/Validation/EnabledMarksValidation.php +++ b/src/Resource/ContentType/Validation/EnabledMarksValidation.php @@ -16,12 +16,34 @@ */ class EnabledMarksValidation implements ValidationInterface { + private const VALID_FIELD_TYPES = ['RichText']; + + /** + * @var array + */ + private $enabledMarks; + + public function __construct(array $enabledMarks) + { + $this->enabledMarks = $enabledMarks; + } + /** * {@inheritdoc} */ public static function getValidFieldTypes(): array { - return []; + return self::VALID_FIELD_TYPES; + } + + public function getEnabledMarks(): array + { + return $this->enabledMarks; + } + + public function setEnabledMarks(array $enabledMarks) + { + $this->enabledMarks = $enabledMarks; } /** @@ -29,6 +51,6 @@ public static function getValidFieldTypes(): array */ public function jsonSerialize() { - return []; + return ['enabledMarks' => $this->enabledMarks]; } } diff --git a/src/Resource/ContentType/Validation/EnabledNodeTypesValidation.php b/src/Resource/ContentType/Validation/EnabledNodeTypesValidation.php index 7bfe1d27..8c550d5f 100644 --- a/src/Resource/ContentType/Validation/EnabledNodeTypesValidation.php +++ b/src/Resource/ContentType/Validation/EnabledNodeTypesValidation.php @@ -16,12 +16,34 @@ */ class EnabledNodeTypesValidation implements ValidationInterface { + private const VALID_FIELD_TYPES = ['RichText']; + + /** + * @var array + */ + private $enabledNodeTypes; + + public function __construct(array $enabledNodeTypes) + { + $this->enabledNodeTypes = $enabledNodeTypes; + } + /** * {@inheritdoc} */ public static function getValidFieldTypes(): array { - return []; + return self::VALID_FIELD_TYPES; + } + + public function getEnabledNodeTypes(): array + { + return $this->enabledNodeTypes; + } + + public function setEnabledNodeTypes(array $enabledNodeTypes) + { + $this->enabledNodeTypes = $enabledNodeTypes; } /** @@ -29,6 +51,6 @@ public static function getValidFieldTypes(): array */ public function jsonSerialize() { - return []; + return ['enabledNodeTypes' => $this->enabledNodeTypes]; } } diff --git a/src/Resource/ContentType/Validation/InValidation.php b/src/Resource/ContentType/Validation/InValidation.php index cf51a37b..a9ba7609 100644 --- a/src/Resource/ContentType/Validation/InValidation.php +++ b/src/Resource/ContentType/Validation/InValidation.php @@ -22,7 +22,7 @@ * - Integer * - Number */ -class InValidation implements ValidationInterface +class InValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var string[] @@ -72,8 +72,11 @@ public static function getValidFieldTypes(): array */ public function jsonSerialize(): array { - return [ - 'in' => $this->values, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'in' => $this->values, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/LinkContentTypeValidation.php b/src/Resource/ContentType/Validation/LinkContentTypeValidation.php index 484e3fe7..2bb64781 100644 --- a/src/Resource/ContentType/Validation/LinkContentTypeValidation.php +++ b/src/Resource/ContentType/Validation/LinkContentTypeValidation.php @@ -11,6 +11,10 @@ namespace Contentful\Management\Resource\ContentType\Validation; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EmbeddedEntryBlockValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EmbeddedEntryInlineValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EntryHyperlinkValidationInterface; + /** * LinkContentTypeValidation class. * @@ -20,7 +24,10 @@ * Applicable to: * - Link (to entries) */ -class LinkContentTypeValidation implements ValidationInterface +class LinkContentTypeValidation extends AbstractCustomMessageValidation implements ValidationInterface, + EntryHyperlinkValidationInterface, + EmbeddedEntryBlockValidationInterface, + EmbeddedEntryInlineValidationInterface { /** * @var string[] @@ -70,8 +77,11 @@ public static function getValidFieldTypes(): array */ public function jsonSerialize(): array { - return [ - 'linkContentType' => $this->contentTypes, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'linkContentType' => $this->contentTypes, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/LinkMimetypeGroupValidation.php b/src/Resource/ContentType/Validation/LinkMimetypeGroupValidation.php index 3c1ee1b3..9df1897f 100644 --- a/src/Resource/ContentType/Validation/LinkMimetypeGroupValidation.php +++ b/src/Resource/ContentType/Validation/LinkMimetypeGroupValidation.php @@ -20,7 +20,7 @@ * Applicable to: * - Link (to assets) */ -class LinkMimetypeGroupValidation implements ValidationInterface +class LinkMimetypeGroupValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var string[] @@ -70,8 +70,11 @@ public static function getValidFieldTypes(): array */ public function jsonSerialize(): array { - return [ - 'linkMimetypeGroup' => $this->mimeTypeGroups, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'linkMimetypeGroup' => $this->mimeTypeGroups, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/Nodes/AssetHyperlinkValidationInterface.php b/src/Resource/ContentType/Validation/Nodes/AssetHyperlinkValidationInterface.php new file mode 100644 index 00000000..56237942 --- /dev/null +++ b/src/Resource/ContentType/Validation/Nodes/AssetHyperlinkValidationInterface.php @@ -0,0 +1,11 @@ +assetHyperlinkValidations = $assetHyperlinkValidations; + $this->embeddedAssetBlockValidations = $embeddedAssetBlockValidations; + $this->embeddedEntryBlockValidations = $embeddedEntryBlockValidations; + $this->embeddedEntryInlineValidations = $embeddedEntryInlineValidations; + $this->entryHyperlinkValidations = $entryHyperlinkValidations; + } + /** * {@inheritdoc} */ public static function getValidFieldTypes(): array { - return []; + return self::VALID_FIELD_TYPES; + } + + public function getAssetHyperlinkValidations(): array + { + return $this->assetHyperlinkValidations; + } + + public function addAssetHyperlinkValidation(AssetHyperlinkValidationInterface $assetHyperlinkValidation): self + { + $this->assetHyperlinkValidations[] = $assetHyperlinkValidation; + + return $this; + } + + public function resetAssetHyperlinkValidations(): self + { + $this->assetHyperlinkValidations = []; + + return $this; + } + + public function getEmbeddedAssetBlockValidations(): array + { + return $this->embeddedAssetBlockValidations; + } + + public function addEmbeddedAssetBlockValidation( + EmbeddedAssetBlockValidationInterface $embeddedAssetBlockValidation + ): self { + $this->embeddedAssetBlockValidations[] = $embeddedAssetBlockValidation; + + return $this; + } + + public function resetEmbeddedAssetBlockValidations(): self + { + $this->embeddedAssetBlockValidations = []; + + return $this; + } + + public function getEmbeddedEntryBlockValidations(): array + { + return $this->embeddedEntryBlockValidations; + } + + public function addEmbeddedEntryBlockValidation( + EmbeddedEntryBlockValidationInterface $embeddedEntryBlockValidation + ): self { + $this->embeddedEntryBlockValidations[] = $embeddedEntryBlockValidation; + + return $this; + } + + public function resetEmbeddedEntryBlockValidations(): self + { + $this->embeddedEntryBlockValidations = []; + + return $this; + } + + public function getEmbeddedEntryInlineValidations(): array + { + return $this->embeddedEntryInlineValidations; + } + + public function addEmbeddedEntryInlineValidation( + EmbeddedEntryInlineValidationInterface $embeddedEntryInlineValidation + ): self { + $this->embeddedEntryInlineValidations[] = $embeddedEntryInlineValidation; + + return $this; + } + + public function resetEmbeddedEntryInlineValidations(): self + { + $this->embeddedEntryInlineValidations = []; + + return $this; + } + + public function getEntryHyperlinkValidations(): array + { + return $this->entryHyperlinkValidations; + } + + public function addEntryHyperlinkValidation(EntryHyperlinkValidationInterface $entryHyperlinkValidation): self + { + $this->entryHyperlinkValidations[] = $entryHyperlinkValidation; + + return $this; + } + + public function resetEntryHyperlinkValidations(): self + { + $this->entryHyperlinkValidations = []; + + return $this; } /** * {@inheritdoc} */ - public function jsonSerialize() + public function jsonSerialize(): array { - return []; + return [ + 'nodes' => \array_filter( + [ + 'asset-hyperlink' => $this->assetHyperlinkValidations, + 'embedded-asset-block' => $this->embeddedAssetBlockValidations, + 'embedded-entry-block' => $this->embeddedEntryBlockValidations, + 'embedded-entry-inline' => $this->embeddedEntryInlineValidations, + 'entry-hyperlink' => $this->entryHyperlinkValidations, + ] + ), + ]; } } diff --git a/src/Resource/ContentType/Validation/RangeValidation.php b/src/Resource/ContentType/Validation/RangeValidation.php index 35ab02e8..aa78590d 100644 --- a/src/Resource/ContentType/Validation/RangeValidation.php +++ b/src/Resource/ContentType/Validation/RangeValidation.php @@ -20,7 +20,7 @@ * - Integer * - Number */ -class RangeValidation implements ValidationInterface +class RangeValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var int|null @@ -98,8 +98,11 @@ public function jsonSerialize(): array $data['max'] = $this->max; } - return [ - 'range' => $data, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'range' => $data, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/RegexpValidation.php b/src/Resource/ContentType/Validation/RegexpValidation.php index 49b586b0..6c869c09 100644 --- a/src/Resource/ContentType/Validation/RegexpValidation.php +++ b/src/Resource/ContentType/Validation/RegexpValidation.php @@ -20,7 +20,7 @@ * - Symbol * - Text */ -class RegexpValidation implements ValidationInterface +class RegexpValidation extends AbstractCustomMessageValidation implements ValidationInterface { /** * @var string|null @@ -88,8 +88,11 @@ public function jsonSerialize(): array $data['flags'] = $this->flags; } - return [ - 'regexp' => $data, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'regexp' => $data, + ] + ); } } diff --git a/src/Resource/ContentType/Validation/SizeValidation.php b/src/Resource/ContentType/Validation/SizeValidation.php index aedf2d4a..6ff27fd7 100644 --- a/src/Resource/ContentType/Validation/SizeValidation.php +++ b/src/Resource/ContentType/Validation/SizeValidation.php @@ -11,6 +11,12 @@ namespace Contentful\Management\Resource\ContentType\Validation; +use Contentful\Management\Resource\ContentType\Validation\Nodes\AssetHyperlinkValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EmbeddedAssetBlockValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EmbeddedEntryBlockValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EmbeddedEntryInlineValidationInterface; +use Contentful\Management\Resource\ContentType\Validation\Nodes\EntryHyperlinkValidationInterface; + /** * SizeValidation class. * @@ -22,7 +28,12 @@ * - Symbol * - Text */ -class SizeValidation implements ValidationInterface +class SizeValidation extends AbstractCustomMessageValidation implements ValidationInterface, + AssetHyperlinkValidationInterface, + EmbeddedAssetBlockValidationInterface, + EmbeddedEntryBlockValidationInterface, + EmbeddedEntryInlineValidationInterface, + EntryHyperlinkValidationInterface { /** * @var int|null @@ -103,8 +114,11 @@ public function jsonSerialize(): array $data['max'] = $this->max; } - return [ - 'size' => $data, - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'size' => $data, + ] + ); } } diff --git a/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_marks_validation.json b/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_marks_validation.json new file mode 100644 index 00000000..bebabdef --- /dev/null +++ b/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_marks_validation.json @@ -0,0 +1,6 @@ +{ + "enabledMarks": [ + "bold", + "code" + ] +} diff --git a/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_node_types_validation.json b/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_node_types_validation.json new file mode 100644 index 00000000..9a265ffd --- /dev/null +++ b/tests/Fixtures/Unit/Resource/ContentType/Validation/enabled_node_types_validation.json @@ -0,0 +1,7 @@ +{ + "enabledNodeTypes": [ + "heading-1", + "heading-2", + "ordered-list" + ] +} diff --git a/tests/Fixtures/Unit/Resource/ContentType/Validation/nodes_validation.json b/tests/Fixtures/Unit/Resource/ContentType/Validation/nodes_validation.json new file mode 100644 index 00000000..5023d45b --- /dev/null +++ b/tests/Fixtures/Unit/Resource/ContentType/Validation/nodes_validation.json @@ -0,0 +1,55 @@ +{ + "nodes": { + "asset-hyperlink": [ + { + "size": { + "min": 1 + } + } + ], + "embedded-asset-block": [ + { + "size": { + "max": 1 + } + } + ], + "embedded-entry-block": [ + { + "linkContentType": [ + "test" + ] + }, + { + "size": { + "min": 1, + "max": 2 + } + } + ], + "embedded-entry-inline": [ + { + "linkContentType": [ + "test" + ] + }, + { + "size": { + "min": 1 + } + } + ], + "entry-hyperlink": [ + { + "linkContentType": [ + "test" + ] + }, + { + "size": { + "min": 1 + } + } + ] + } +} diff --git a/tests/Unit/Resource/ContentType/Validation/EnabledMarksValidationTest.php b/tests/Unit/Resource/ContentType/Validation/EnabledMarksValidationTest.php new file mode 100644 index 00000000..46591784 --- /dev/null +++ b/tests/Unit/Resource/ContentType/Validation/EnabledMarksValidationTest.php @@ -0,0 +1,37 @@ +assertJsonFixtureEqualsJsonObject('Unit/Resource/ContentType/Validation/enabled_marks_validation.json', $validation); + } + + public function testGetSetData() + { + $validation = new EnabledMarksValidation(['bold', 'code']); + + $this->assertSame(['RichText'], $validation->getValidFieldTypes()); + + $this->assertSame(['bold', 'code'], $validation->getEnabledMarks()); + + $validation->setEnabledMarks(['bold', 'italic']); + $this->assertSame(['bold', 'italic'], $validation->getEnabledMarks()); + } +} diff --git a/tests/Unit/Resource/ContentType/Validation/EnabledNodeTypesValidationTest.php b/tests/Unit/Resource/ContentType/Validation/EnabledNodeTypesValidationTest.php new file mode 100644 index 00000000..6d82c29d --- /dev/null +++ b/tests/Unit/Resource/ContentType/Validation/EnabledNodeTypesValidationTest.php @@ -0,0 +1,60 @@ +assertJsonFixtureEqualsJsonObject( + 'Unit/Resource/ContentType/Validation/enabled_node_types_validation.json', + $validation + ); + } + + public function testGetSetData() + { + $validation = new EnabledNodeTypesValidation(['heading-1', 'heading-2', 'ordered-list']); + + $this->assertSame(['RichText'], $validation->getValidFieldTypes()); + + $this->assertSame(['heading-1', 'heading-2', 'ordered-list'], $validation->getEnabledNodeTypes()); + + $validation->setEnabledNodeTypes( + [ + 'hyperlink', + 'entry-hyperlink', + 'asset-hyperlink', + 'embedded-asset-block', + 'embedded-entry-inline', + 'embedded-entry-block', + ] + ); + + $this->assertSame( + [ + 'hyperlink', + 'entry-hyperlink', + 'asset-hyperlink', + 'embedded-asset-block', + 'embedded-entry-inline', + 'embedded-entry-block', + ], + $validation->getEnabledNodeTypes() + ); + } +} diff --git a/tests/Unit/Resource/ContentType/Validation/NodesValidationTest.php b/tests/Unit/Resource/ContentType/Validation/NodesValidationTest.php new file mode 100644 index 00000000..f4240fde --- /dev/null +++ b/tests/Unit/Resource/ContentType/Validation/NodesValidationTest.php @@ -0,0 +1,83 @@ +assertJsonFixtureEqualsJsonObject( + 'Unit/Resource/ContentType/Validation/nodes_validation.json', + $validation + ); + } + + public function testGetSetData() + { + $sizeValidation = new SizeValidation(1); + $linkContentTypeValidation = new LinkContentTypeValidation(['test']); + + $validation = new NodesValidation( + [$sizeValidation], + [$sizeValidation], + [$linkContentTypeValidation, $sizeValidation], + [$linkContentTypeValidation, $sizeValidation], + [$linkContentTypeValidation, $sizeValidation] + ); + + $this->assertSame(['RichText'], $validation->getValidFieldTypes()); + + $this->assertSame([$sizeValidation], $validation->getAssetHyperlinkValidations()); + $this->assertSame([$sizeValidation], $validation->getEmbeddedAssetBlockValidations()); + $this->assertSame([$linkContentTypeValidation, $sizeValidation], $validation->getEmbeddedEntryBlockValidations()); + $this->assertSame([$linkContentTypeValidation, $sizeValidation], $validation->getEmbeddedEntryInlineValidations()); + $this->assertSame([$linkContentTypeValidation, $sizeValidation], $validation->getEntryHyperlinkValidations()); + } + + public function testGetAddedData() + { + $sizeValidation = new SizeValidation(1); + + $validation = new NodesValidation([], [], [], [], []); + + $this->assertSame([], $validation->getAssetHyperlinkValidations()); + $this->assertSame([], $validation->getEmbeddedAssetBlockValidations()); + $this->assertSame([], $validation->getEmbeddedEntryBlockValidations()); + $this->assertSame([], $validation->getEmbeddedEntryInlineValidations()); + $this->assertSame([], $validation->getEntryHyperlinkValidations()); + + $validation->addAssetHyperlinkValidation($sizeValidation); + $validation->addEmbeddedAssetBlockValidation($sizeValidation); + $validation->addEmbeddedEntryBlockValidation($sizeValidation); + $validation->addEmbeddedEntryInlineValidation($sizeValidation); + $validation->addEntryHyperlinkValidation($sizeValidation); + + $this->assertSame([$sizeValidation], $validation->getAssetHyperlinkValidations()); + $this->assertSame([$sizeValidation], $validation->getEmbeddedAssetBlockValidations()); + $this->assertSame([$sizeValidation], $validation->getEmbeddedEntryBlockValidations()); + $this->assertSame([$sizeValidation], $validation->getEmbeddedEntryInlineValidations()); + $this->assertSame([$sizeValidation], $validation->getEntryHyperlinkValidations()); + } +}