Skip to content

Commit

Permalink
Do not use dynamic settings injection to avoid config resolver warning (
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric authored and andrerom committed Jul 9, 2019
1 parent e8c8482 commit 57122d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 1 addition & 2 deletions bundle/Resources/config/fieldtype_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ services:
class: "%ezpublish.fieldType.ezxmltext.converter.html5.class%"
arguments:
- "%ezpublish.fieldType.ezxmltext.converter.html5.resources%"
calls:
- [ setCustomStylesheets, [ "$fieldtypes.ezxml.custom_xsl$" ] ]
- "@ezpublish.config.resolver"

ezpublish.fieldType.ezxmltext.converter.expanding:
class: "%ezpublish.fieldType.ezxmltext.converter.expanding.class%"
Expand Down
12 changes: 11 additions & 1 deletion lib/FieldType/XmlText/Converter/Html5.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use eZ\Publish\Core\FieldType\XmlText\Converter;
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
use DOMDocument;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use XSLTProcessor;
use RuntimeException;

Expand All @@ -28,6 +29,11 @@ class Html5 implements Converter
*/
protected $stylesheet;

/**
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface
*/
protected $configResolver;

/**
* Array of XSL stylesheets to add to the main one, grouped by priority.
*
Expand All @@ -51,14 +57,16 @@ class Html5 implements Converter
* Constructor.
*
* @param string $stylesheet Stylesheet to use for conversion
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver
* @param array $customStylesheets Array of XSL stylesheets. Each entry consists in a hash having "path" and "priority" keys.
* @param \eZ\Publish\Core\FieldType\XmlText\Converter[] $preConverters Array of pre-converters
*
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
*/
public function __construct($stylesheet, array $customStylesheets = [], array $preConverters = [])
public function __construct($stylesheet, ConfigResolverInterface $configResolver, array $customStylesheets = [], array $preConverters = [])
{
$this->stylesheet = $stylesheet;
$this->configResolver = $configResolver;
$this->setCustomStylesheets($customStylesheets);

foreach ($preConverters as $preConverter) {
Expand Down Expand Up @@ -131,6 +139,8 @@ protected function getXSLTProcessor()
// Now loading custom xsl stylesheets dynamically.
// According to XSL spec, each <xsl:import> tag MUST be loaded BEFORE any other element.
$insertBeforeEl = $xslDoc->documentElement->firstChild;

$this->setCustomStylesheets($this->configResolver->getParameter('fieldtypes.ezxml.custom_xsl'));
foreach ($this->getSortedCustomStylesheets() as $stylesheet) {
if (!file_exists($stylesheet)) {
throw new RuntimeException("Cannot find XSL stylesheet for XMLText rendering: $stylesheet");
Expand Down
14 changes: 11 additions & 3 deletions tests/lib/FieldType/Converter/Html5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking;
use eZ\Publish\Core\FieldType\XmlText\Converter\Html5;
use eZ\Publish\Core\FieldType\XmlText\Converter;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use PHPUnit\Framework\TestCase;
use DOMDocument;
use DOMNodeList;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function testConstructorException(array $preConverters)
{
$this->expectException(\eZ\Publish\Core\Base\Exceptions\InvalidArgumentType::class);

new Html5('', [], $preConverters);
new Html5('', $this->getMockBuilder(ConfigResolverInterface::class)->getMock(), [], $preConverters);
}

public function testPreConverterCalled()
Expand All @@ -84,6 +85,7 @@ public function testPreConverterCalled()

$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
$preConverterMock1,
Expand Down Expand Up @@ -149,7 +151,7 @@ public function testAnchorRendering($xml, $xpathCheck, $checkClosure)
{
$dom = new DomDocument();
$dom->loadXML($xml);
$html5 = new Html5($this->getDefaultStylesheet(), []);
$html5 = new Html5($this->getDefaultStylesheet(), $this->getMockBuilder(ConfigResolverInterface::class)->getMock(), []);

$result = new DomDocument();
$result->loadXML($html5->convert($dom));
Expand Down Expand Up @@ -213,6 +215,7 @@ public function testLiteralRendering($xml, $xpathCheck, $checkClosure)
$dom->loadXML($xml);
$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand All @@ -235,6 +238,7 @@ public function testConvertReturnsNotValidXml()
);
$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand All @@ -255,6 +259,7 @@ public function testConvertReturnsNotValidXml()
);
$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand All @@ -272,7 +277,7 @@ public function testConvertReturnsNotValidXml()

public function testAddPreConverter()
{
$html5Converter = new Html5('foo.xsl');
$html5Converter = new Html5('foo.xsl', $this->getMockBuilder(ConfigResolverInterface::class)->getMock());
$converter1 = $this->getPreConvertMock();
$html5Converter->addPreConverter($converter1);
$converter2 = $this->getPreConvertMock();
Expand Down Expand Up @@ -329,6 +334,7 @@ public function testTableRendering()

$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand Down Expand Up @@ -407,6 +413,7 @@ public function testEmbedRendering($xml, $expected)

$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand Down Expand Up @@ -474,6 +481,7 @@ public function testConvert($inputFilePath, $outputFilePath)

$html5 = new Html5(
$this->getDefaultStylesheet(),
$this->getMockBuilder(ConfigResolverInterface::class)->getMock(),
[],
[
new Expanding(),
Expand Down

0 comments on commit 57122d9

Please sign in to comment.