Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions src/lib/RichText/Validator/CustomTemplateValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,16 @@
*/
final class CustomTemplateValidator implements ValidatorInterface
{
/**
* Custom Tags global configuration (ibexa.richtext.custom_tags Semantic Config).
*
* @var array<string,array{template:string, is_inline:bool, icon:string, attributes:array<string, array{type: string, required: bool, default_value: mixed}>}>
*/
private array $customTagsConfiguration;

/**
* Custom Styles global configuration (ibexa.richtext.custom_styles Semantic Config).
*
* @var array<string,array{template:string,inline:bool}>
*/
private array $customStylesConfiguration;

/**
* CustomTemplateValidator constructor.
*
* @param array<string,array{template:string, is_inline:bool, icon:string, attributes:array<string, array{type: string, required: bool, default_value: mixed}>}> $customTagsConfiguration
* @param array<string,array{template:string, inline:bool}> $customStylesConfiguration
*/
public function __construct(
array $customTagsConfiguration,
array $customStylesConfiguration
private readonly array $customTagsConfiguration,
private readonly array $customStylesConfiguration
) {
$this->customTagsConfiguration = $customTagsConfiguration;
$this->customStylesConfiguration = $customStylesConfiguration;
}

/**
Expand Down Expand Up @@ -76,16 +60,12 @@ public function validateDocument(DOMDocument $xmlDocument): array
}

if (!in_array($tagName, $configuredTemplateNames, true)) {
@trigger_error(
"Configuration for RichText Custom Tag or Custom Style '{$tagName}' not found. " .
'Custom Tags and Custom Style configuration is required since 7.1, its lack will result in validation error in 8.x',
E_USER_DEPRECATED
);
$errors[] = "Missing configuration for RichText CustomTag or CustomStyle: '$tagName'";
continue;
}

// Custom Styles does not have any attributes, so we can skip validation for them
if (isset($this->customStylesConfiguration[$tagName])) {
if(isset($this->customStylesConfiguration[$tagName])) {
continue;
}

Expand Down
36 changes: 6 additions & 30 deletions tests/lib/RichText/Validator/CustomTemplateValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
use Symfony\Component\Yaml\Yaml;

/**
* Test RichText CustomTemplateValidator.
*
* @see \Ibexa\FieldTypeRichText\FieldType\RichText\CustomTemplateValidator
* @covers \Ibexa\FieldTypeRichText\FieldType\RichText\CustomTemplateValidator
*/
class CustomTemplateValidatorTest extends TestCase
final class CustomTemplateValidatorTest extends TestCase
{
private CustomTemplateValidator $validator;

Expand Down Expand Up @@ -127,7 +125,9 @@ public function providerForTestValidateDocument(): array
</section>
DOCBOOK
),
[],
[
"Missing configuration for RichText CustomTag or CustomStyle: 'non_existing_style'",
],
],
[
$this->createDocument(
Expand Down Expand Up @@ -205,6 +205,7 @@ public function providerForTestValidateDocument(): array
),
[
'Missing RichText Custom Tag name',
"Missing configuration for RichText CustomTag or CustomStyle: 'undefined_tag'",
"Missing attribute name for RichText Custom Tag 'video'",
"The attribute 'title' of RichText Custom Tag 'video' cannot be empty",
"The attribute 'width' of RichText Custom Tag 'video' cannot be empty",
Expand All @@ -214,31 +215,6 @@ public function providerForTestValidateDocument(): array
];
}

/**
* Test that defined but not configured yet Custom Tag doesn't cause validation error.
*/
public function testValidateDocumentAcceptsLegacyTags(): void
{
$document = $this->createDocument(
<<<DOCBOOK
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml"
xmlns:ezcustom="http://ibexa.co/xmlns/dxp/docbook/custom"
version="5.0-variant ezpublish-1.0">
<eztemplate name="undefined_tag">
<ezcontent>Undefined</ezcontent>
<ezconfig>
<ezvalue key="title">Test</ezvalue>
</ezconfig>
</eztemplate>
</section>
DOCBOOK
);

self::assertEmpty($this->validator->validateDocument($document));
}

protected function createDocument(string $source): DOMDocument
{
$document = new DOMDocument();
Expand Down
Loading