Skip to content

Commit

Permalink
Merge pull request ezsystems#1087 from ezsystems/fix-EZP-23513-xmltex…
Browse files Browse the repository at this point in the history
…t-paragraphs

Fix EZP-23513: embed rendering (XmlText)
  • Loading branch information
pspanja committed Nov 27, 2014
2 parents ea728cd + e8c7dd4 commit a40b252
Show file tree
Hide file tree
Showing 118 changed files with 3,333 additions and 239 deletions.
Expand Up @@ -27,9 +27,38 @@ public function process( ContainerBuilder $container )
}

$html5ConverterDef = $container->getDefinition( 'ezpublish.fieldType.ezxmltext.converter.html5' );
foreach ( $container->findTaggedServiceIds( 'ezpublish.ezxml.converter' ) as $id => $attributes )
$taggedServiceIds = $container->findTaggedServiceIds( 'ezpublish.ezxml.converter' );

$converterIdsByPriority = array();
foreach ( $taggedServiceIds as $id => $tags )
{
foreach ( $tags as $tag )
{
$priority = isset( $tag['priority'] ) ? (int)$tag['priority'] : 0;
$converterIdsByPriority[$priority][] = $id;
}
}

$converterIdsByPriority = $this->sortConverterIds( $converterIdsByPriority );

foreach ( $converterIdsByPriority as $referenceId )
{
$html5ConverterDef->addMethodCall( 'addPreConverter', array( new Reference( $id ) ) );
$html5ConverterDef->addMethodCall( 'addPreConverter', array( new Reference( $referenceId ) ) );
}
}

/**
* Transforms a two-dimensional array of converters, indexed by priority,
* into a flat array of Reference objects.
*
* @param array $converterIdsByPriority
*
* @return \Symfony\Component\DependencyInjection\Reference[]
*/
protected function sortConverterIds( array $converterIdsByPriority )
{
krsort( $converterIdsByPriority, SORT_NUMERIC );

return call_user_func_array( 'array_merge', $converterIdsByPriority );
}
}
Expand Up @@ -17,7 +17,8 @@ parameters:
ezpublish.fieldType.ezxmltext.converter.embedToHtml5.class: eZ\Publish\Core\FieldType\XmlText\Converter\EmbedToHtml5
ezpublish.fieldType.ezxmlText.converter.embedToHtml5.excludedAttributes: [view, node_id, object_id]
ezpublish.fieldType.ezxmltext.converter.ezLinkToHtml5.class: eZ\Publish\Core\FieldType\XmlText\Converter\EzLinkToHtml5
ezpublish.fieldType.ezxmltext.converter.customTags.class: eZ\Publish\Core\FieldType\XmlText\Converter\CustomTags
ezpublish.fieldType.ezxmltext.converter.expanding.class: eZ\Publish\Core\FieldType\XmlText\Converter\Expanding
ezpublish.fieldType.ezxmltext.converter.embedLinking.class: eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking

# RichText
ezpublish.fieldType.ezrichtext.converter.xslt.class: eZ\Publish\Core\FieldType\RichText\Converter\Xslt
Expand Down Expand Up @@ -104,15 +105,15 @@ services:
- %ezpublish.fieldType.ezxmltext.converter.html5.resources%
- @ezpublish.config.resolver

ezpublish.fieldType.ezxmltext.converter.embedToHtml5:
class: %ezpublish.fieldType.ezxmltext.converter.embedToHtml5.class%
arguments:
- @fragment.handler
- @ezpublish.api.repository
- %ezpublish.fieldType.ezxmlText.converter.embedToHtml5.excludedAttributes%
- @?logger
ezpublish.fieldType.ezxmltext.converter.expanding:
class: %ezpublish.fieldType.ezxmltext.converter.expanding.class%
tags:
- { name: ezpublish.ezxml.converter, priority: 32 }

ezpublish.fieldType.ezxmltext.converter.embedLinking:
class: %ezpublish.fieldType.ezxmltext.converter.embedLinking.class%
tags:
- { name: ezpublish.ezxml.converter }
- { name: ezpublish.ezxml.converter, priority: 24 }

ezpublish.fieldType.ezxmltext.converter.ezLinkToHtml5:
class: %ezpublish.fieldType.ezxmltext.converter.ezLinkToHtml5.class%
Expand All @@ -122,12 +123,17 @@ services:
- @ezpublish.urlalias_router
- @?logger
tags:
- { name: ezpublish.ezxml.converter }
- { name: ezpublish.ezxml.converter, priority: 16 }

ezpublish.fieldType.ezxmltext.converter.customTags:
class: %ezpublish.fieldType.ezxmltext.converter.customTags.class%
ezpublish.fieldType.ezxmltext.converter.embedToHtml5:
class: %ezpublish.fieldType.ezxmltext.converter.embedToHtml5.class%
arguments:
- @fragment.handler
- @ezpublish.api.repository
- %ezpublish.fieldType.ezxmlText.converter.embedToHtml5.excludedAttributes%
- @?logger
tags:
- { name: ezpublish.ezxml.converter }
- { name: ezpublish.ezxml.converter, priority: 8 }

# RichText
ezpublish.fieldType.ezrichtext.converter.input.ezxml:
Expand Down
Expand Up @@ -67,4 +67,55 @@ public function testAddPreConverter()
array( new Reference( $serviceId ) )
);
}

public function testSortConverterIds()
{
$container = new ContainerBuilder();
$html5ConvertDef = $this->getMock(
'Symfony\\Component\\DependencyInjection\\Definition',
array(
'addMethodCall',
)
);
$container->setDefinition( 'ezpublish.fieldType.ezxmltext.converter.html5', $html5ConvertDef );

$preConverterDef1 = new Definition();
$preConverterDef1->addTag( 'ezpublish.ezxml.converter', array( 'priority' => 10 ) );
$container->setDefinition( 'foo.converter1', $preConverterDef1 );

$preConverterDef2 = new Definition();
$preConverterDef2->addTag( 'ezpublish.ezxml.converter', array( 'priority' => 5 ) );
$container->setDefinition( 'foo.converter2', $preConverterDef2 );

$preConverterDef3 = new Definition();
$preConverterDef3->addTag( 'ezpublish.ezxml.converter', array( 'priority' => 15 ) );
$container->setDefinition( 'foo.converter3', $preConverterDef3 );

$html5ConvertDef
->expects( $this->at( 0 ) )
->method( 'addMethodCall' )
->with(
'addPreConverter',
array( new Reference( 'foo.converter3' ) )
);

$html5ConvertDef
->expects( $this->at( 1 ) )
->method( 'addMethodCall' )
->with(
'addPreConverter',
array( new Reference( 'foo.converter1' ) )
);

$html5ConvertDef
->expects( $this->at( 2 ) )
->method( 'addMethodCall' )
->with(
'addPreConverter',
array( new Reference( 'foo.converter2' ) )
);

$pass = new XmlTextConverterPass();
$pass->process( $container );
}
}

This file was deleted.

@@ -0,0 +1,84 @@
<?php
/**
* File containing the EmbedLinking converter test
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

namespace eZ\Publish\Core\FieldType\Tests\XmlText\Converter;

use eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking;
use PHPUnit_Framework_TestCase;
use DOMDocument;

/**
* Tests the EmbedLinking converter
*/
class EmbedLinkingTest extends PHPUnit_Framework_TestCase
{
/**
* Provider for conversion test.
*
* @return array
*/
public function providerForTestConvert()
{
$map = array();

foreach ( glob( __DIR__ . "/_fixtures/embed_linking/input/*.xml" ) as $inputFilePath )
{
$basename = basename( $inputFilePath, ".xml" );
$outputFilePath = __DIR__ . "/_fixtures/embed_linking/output/{$basename}.xml";

$map[] = array( $inputFilePath, $outputFilePath );
}

return $map;
}

/**
* @param string $xml
* @param boolean $isPath
*
* @return \DOMDocument
*/
protected function createDocument( $xml, $isPath = true )
{
$document = new DOMDocument();

$document->preserveWhiteSpace = false;
$document->formatOutput = false;

if ( $isPath === true )
{
$xml = file_get_contents( $xml );
}

$document->loadXml( $xml );

return $document;
}

/**
* @param string $inputFilePath
* @param string $outputFilePath
*
* @dataProvider providerForTestConvert
*/
public function testConvert( $inputFilePath, $outputFilePath )
{
$inputDocument = $this->createDocument( $inputFilePath );

$converter = new EmbedLinking();
$converter->convert( $inputDocument );

$outputDocument = $this->createDocument( $outputFilePath );

$this->assertEquals(
$outputDocument,
$inputDocument
);
}
}

0 comments on commit a40b252

Please sign in to comment.