Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected RichText Validator from DIC into RichText Converter #91

Merged
merged 8 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ services:
arguments:
- "@ezpublish.api.repository"
- "@?logger"
- "@ezpublish.fieldType.ezrichtext.validator.docbook"
36 changes: 11 additions & 25 deletions lib/FieldType/XmlText/Converter/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Psr\Log\NullLogger;
use Psr\Log\LogLevel;
use Symfony\Component\Debug\Exception\ContextErrorException;
use eZ\Publish\Core\SignalSlot\Repository;

class RichText implements Converter
{
Expand All @@ -36,7 +37,7 @@ class RichText implements Converter
*/
private $imageContentTypes;
/**
* @var \eZ\Publish\Core\FieldType\RichText\Validator
* @var Validator
*/
private $validator;

Expand Down Expand Up @@ -64,17 +65,22 @@ class RichText implements Converter

/**
* RichText constructor.
* @param null $apiRepository
* @param Repository $apiRepository
* @param LoggerInterface|null $logger
* @param Validator $validator
*/
public function __construct($apiRepository = null, LoggerInterface $logger = null)
{
public function __construct(
Repository $apiRepository = null,
LoggerInterface $logger = null,
Validator $validator = null
) {
$this->validator = $validator;

$this->logger = $logger instanceof LoggerInterface ? $logger : new NullLogger();
$this->imageContentTypes = [];
$this->apiRepository = $apiRepository;

$this->styleSheets = null;
$this->validator = null;
$this->converter = null;
$this->customTagsLog = [self::INLINE_CUSTOM_TAG => [], self::BLOCK_CUSTOM_TAG => []];
}
Expand Down Expand Up @@ -116,31 +122,11 @@ public function setCustomStylesheets(array $customStylesheets = [])
$this->converter = null;
}

/**
* @param array $customValidators
*/
public function setCustomValidators(array $customValidators = [])
{
$validators = array_merge(
[
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
],
$customValidators,
[
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
]
);
$this->validator = new Validator($validators);
}

protected function getConverter()
{
if ($this->styleSheets === null) {
$this->setCustomStylesheets([]);
}
if ($this->validator === null) {
$this->setCustomValidators([]);
}
if ($this->converter === null) {
$this->converter = new Aggregate(
[
Expand Down
32 changes: 19 additions & 13 deletions tests/lib/FieldType/Converter/EzxmlToDocbookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace EzSystems\EzPlatformXmlTextFieldType\Tests\FieldType\Converter;

use eZ\Publish\Core\FieldType\RichText\Validator;
use eZ\Publish\Core\FieldType\XmlText\Converter\RichText;
use eZ\Publish\Core\SignalSlot\Repository;
use eZ\Publish\API\Repository\ContentService;
Expand Down Expand Up @@ -56,25 +57,30 @@ private function createApiRepositoryStub()
*/
protected function getConverter($inputFile)
{
$validatorSchemas = [
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
];
$apiRepositoryStub = $this->createApiRepositoryStub();

if (basename($inputFile) === '017-customYoutube.xml') {
$apiRepositoryStub = $this->createApiRepositoryStub();
$customStylesheets =
$customStylesheets = [
[
[
'path' => __DIR__ . '/Xslt/_fixtures/ezxml/custom_stylesheets/youtube_docbook.xsl',
'priority' => 100,
],
];
$customValidators = [__DIR__ . '/../../../../tests/lib/FieldType/Converter/Xslt/_fixtures/docbook/custom_schemas/youtube.rng'];
$converter = new RichText($apiRepositoryStub);
$converter->setCustomStylesheets($customStylesheets);
$converter->setCustomValidators($customValidators);
'path' => __DIR__ . '/Xslt/_fixtures/ezxml/custom_stylesheets/youtube_docbook.xsl',
'priority' => 100,
],
];
$validatorSchemas[] = __DIR__ . '/../../../../tests/lib/FieldType/Converter/Xslt/_fixtures/docbook/custom_schemas/youtube.rng';

$validator = new Validator($validatorSchemas);
$converter = new RichText($apiRepositoryStub, null, $validator);
$converter->setCustomStylesheets($customStylesheets);
return $converter;
}

if ($this->converter === null) {
$apiRepositoryStub = $this->createApiRepositoryStub();
$this->converter = new RichText($apiRepositoryStub);
$validator = new Validator($validatorSchemas);
$this->converter = new RichText($apiRepositoryStub, null, $validator);
}

return $this->converter;
Expand Down
17 changes: 15 additions & 2 deletions tests/lib/FieldType/Converter/RichTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use eZ\Publish\API\Repository\Values\Content\Location;
use Psr\Log\NullLogger;
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use eZ\Publish\Core\FieldType\RichText\Validator;

class RichTextTest extends TestCase
{
Expand Down Expand Up @@ -224,9 +225,10 @@ public function testConvert($inputFilePath, $outputFilePath, $logFilePath)
{
$apiRepositoryStub = $this->createApiRepositoryStub();
$loggerStub = $this->createLoggerStub($logFilePath);
$validator = $this->getValidator();

$inputDocument = $this->createDocument($inputFilePath);
$richText = new RichText($apiRepositoryStub, $loggerStub);
$richText = new RichText($apiRepositoryStub, $loggerStub, $validator);
$richText->setImageContentTypes([27]);

$result = $richText->convert($inputDocument, true, true);
Expand All @@ -252,6 +254,16 @@ public function testConvert($inputFilePath, $outputFilePath, $logFilePath)
);
}

public function getValidator()
{
return new Validator(
array(
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng',
'./vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/docbook.iso.sch.xsl',
)
);
}

/**
* @param string $inputFilePath
* @param string $outputFilePath
Expand All @@ -261,9 +273,10 @@ public function testConvert($inputFilePath, $outputFilePath, $logFilePath)
public function testTagEmbeddedImages($inputFilePath, $outputFilePath)
{
$apiRepositoryStub = $this->createApiRepositoryStub();
$validator = $this->getValidator();

$inputDocument = $this->createDocument($inputFilePath);
$richText = new RichText($apiRepositoryStub);
$richText = new RichText($apiRepositoryStub, null, $validator);
$richText->setImageContentTypes(array(27));

$richText->tagEmbeddedImages($inputDocument, null);
Expand Down