Skip to content

Commit

Permalink
EZP 21054: Added (failing) unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Jul 22, 2013
1 parent 36ef7a9 commit 91e5c67
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions eZ/Publish/Core/FieldType/Tests/XmlText/Converter/Html5Test.php
Expand Up @@ -12,6 +12,8 @@
use eZ\Publish\Core\FieldType\XmlText\Converter\Html5;
use PHPUnit_Framework_TestCase;
use DomDocument;
use DomNodeList;
use DomXPath;

/**
* Tests the Html5 converter
Expand All @@ -24,7 +26,7 @@ protected function getDefaultStylesheet()
return __DIR__ . '../../../../XmlText/Input/Resources/stylesheets/eZXml2Html5_core.xsl';
}

protected function getPreConvertMock()
protected function getPreConvertMock()
{
return $this->getMockBuilder( 'eZ\Publish\Core\FieldType\XmlText\Converter' )
->getMock();
Expand All @@ -50,7 +52,6 @@ public function testConstructorException( array $preConverters )
new Html5( '', $preConverters );
}


public function testPreConverterCalled()
{
$dom = new DomDocument();
Expand All @@ -74,4 +75,71 @@ public function testPreConverterCalled()
);
$html5->convert( $dom );
}

public function dataProviderAnchor()
{
$that = $this;
return array(
array(
'<?xml version="1.0" encoding="utf-8"?>
<section xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"><anchor name="start"/>This is the start</paragraph></section>',
'//a[@id="start"]',
function ( DOMNodeList $xpathResult ) use ( $that )
{
$that->assertEquals( $xpathResult->length, 1 );
$anchor = $xpathResult->item( 0 );
$that->assertEquals( $anchor->parentNode->localName, 'p' );
}
),
array(
'<?xml version="1.0" encoding="utf-8"?>
<section xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
<paragraph><anchor name="start"/>This is<anchor name="middle"/> the start<anchor name="end"/></paragraph>
</section>',
'//a[@id]',
function ( DOMNodeList $xpathResult ) use ( $that )
{
$ids = array( 'start', 'middle', 'end' );
$that->assertEquals( $xpathResult->length, count( $ids ) );
foreach ( $xpathResult as $k => $anchor )
{
$that->assertEquals(
$anchor->getAttribute( 'id' ),
$ids[$k]
);
$that->assertEquals( $anchor->parentNode->localName, 'p' );
}
}
),
array(
'<?xml version="1.0" encoding="utf-8"?>
<section xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">This is a long line with <anchor name="inside"/> an anchor in the middle</paragraph></section>',
'//a[@id="inside"]',
function ( DOMNodeList $xpathResult ) use ( $that )
{
$that->assertEquals( $xpathResult->length, 1 );
$doc = $xpathResult->item( 0 )->ownerDocument;
$that->assertEquals(
trim( $doc->saveXML( $doc->documentElement ) ),
'<p>This is a long line with <a id="inside"/> an anchor in the middle</p>'
);
}
)
);
}

/**
* @dataProvider dataProviderAnchor
*/
public function testAnchorRendering( $xml, $xpathCheck, $checkClosure )
{
$dom = new DomDocument();
$dom->loadXML( $xml );
$html5 = new Html5( $this->getDefaultStylesheet(), array() );

$result = new DomDocument();
$result->loadXML( $html5->convert( $dom ) );
$xpath = new DomXPath( $result );
$checkClosure( $xpath->query( $xpathCheck ) );
}
}

0 comments on commit 91e5c67

Please sign in to comment.