Skip to content

Commit

Permalink
EZP-28959: Prevent publishing errors on pre-existing, undefined Custo…
Browse files Browse the repository at this point in the history
…m Tags (ezsystems#2291)

* EZP-28959: Replaced validation error with deprecation notice due to BC

* EZP-28959: Aligned tests with the fix
  • Loading branch information
alongosz committed Mar 26, 2018
1 parent ab3855d commit ec2de6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
Expand Up @@ -667,14 +667,7 @@ public function testCreateContentWithInvalidCustomTag(
$invalidXmlDocument = $this->createDocument($xmlDocumentPath);
$this->createContent(new RichTextValue($invalidXmlDocument));
} catch (ContentFieldValidationException $e) {
// get first nested ValidationError
/** @var \eZ\Publish\SPI\FieldType\ValidationError $error */
$error = current(current(current($e->getFieldErrors())));

self::assertEquals(
$expectedValidationMessage,
$error->getTranslatableMessage()->message
);
$this->assertValidationErrorOccurs($e, $expectedValidationMessage);

return;
}
Expand All @@ -690,10 +683,6 @@ public function testCreateContentWithInvalidCustomTag(
public function providerForTestCreateContentWithInvalidCustomTag()
{
$data = [
[
__DIR__ . '/_fixtures/ezrichtext/custom_tags/invalid/unknown_tag.xml',
"Unknown RichText Custom Tag 'unknown_tag'",
],
[
__DIR__ . '/_fixtures/ezrichtext/custom_tags/invalid/equation.xml',
"The attribute 'processor' of RichText Custom Tag 'equation' cannot be empty",
Expand Down
8 changes: 6 additions & 2 deletions eZ/Publish/Core/FieldType/RichText/CustomTagsValidator.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $customTagsConfiguration)
*
* @return string[] an array of error messages
*/
public function validateDocument(DOMDocument $xmlDocument)
public function validateDocument(DOMDocument $xmlDocument): array
{
$errors = [];

Expand All @@ -56,7 +56,11 @@ public function validateDocument(DOMDocument $xmlDocument)
}

if (!isset($this->customTagsConfiguration[$tagName])) {
$errors[] = "Unknown RichText Custom Tag '{$tagName}'";
@trigger_error(
"Configuration for RichText Custom Tag '{$tagName}' not found. " .
'Custom Tags configuration is required since 7.1, its lack will result in validation error in 8.x',
E_USER_DEPRECATED
);
continue;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@
class CustomTagsValidatorTest extends TestCase
{
/**
* @var CustomTagsValidator
* @var \eZ\Publish\Core\FieldType\RichText\CustomTagsValidator
*/
private $validator;

Expand All @@ -37,7 +37,7 @@ public function setUp()
/**
* Test validating DocBook document containing Custom Tags.
*
* @covers \CustomTagsValidator::validateDocument
* @covers \eZ\Publish\Core\FieldType\RichText\CustomTagsValidator::validateDocument
*
* @dataProvider providerForTestValidateDocument
*
Expand Down Expand Up @@ -83,27 +83,6 @@ public function providerForTestValidateDocument()
$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://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/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
),
[
"Unknown RichText Custom Tag 'undefined_tag'",
],
],
[
$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://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
Expand Down Expand Up @@ -199,7 +178,6 @@ public function providerForTestValidateDocument()
),
[
'Missing RichText Custom Tag name',
"Unknown RichText Custom Tag '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 @@ -209,6 +187,31 @@ public function providerForTestValidateDocument()
];
}

/**
* Test that defined but not configured yet Custom Tag doesn't cause validation error.
*/
public function testValidateDocumentAcceptsLegacyTags()
{
$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://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/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));
}

/**
* @param string $source XML source
*
Expand Down

0 comments on commit ec2de6b

Please sign in to comment.