Skip to content

Commit

Permalink
Update sample.html and testLoadHtml
Browse files Browse the repository at this point in the history
Update sample.html to use HTML5 sample.html with doctype.
Update testLoadHtml to detect the presence of elements of sample.html and test if its content is correct.
  • Loading branch information
alphp committed Jun 2, 2018
1 parent 9f655e4 commit 9cddc7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 5 additions & 2 deletions tests/Fixture/sample.html
@@ -1,4 +1,6 @@
<html><body>
<!DOCTYPE html>
<html>
<body>

<p>Browsers usually indent blockquote elements.</p>

Expand All @@ -10,4 +12,5 @@
close to 5 million globally.
</blockquote>

</body></html>
</body>
</html>
25 changes: 19 additions & 6 deletions tests/TestCase/Utility/XmlTest.php
Expand Up @@ -254,15 +254,28 @@ public function testBuildEmptyTag()
*/
public function testLoadHtml()
{
$html = CORE_TESTS . 'Fixture/sample.html';
$html = file_get_contents($html);
$html_file = CORE_TESTS . 'Fixture/sample.html';
$html = file_get_contents($html_file);
$paragraph = 'Browsers usually indent blockquote elements.';
$blockquote = "
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
";

$xml = Xml::loadHtml($html);
$xml = html_entity_decode($xml->asXML(), ENT_NOQUOTES, 'UTF-8');
$this->assertEquals($html, $xml);
$this->assertTrue(isset($xml->body->p), 'Paragraph present');
$this->assertEquals($paragraph, (string) $xml->body->p);
$this->assertTrue(isset($xml->body->blockquote), 'Blockquote present');
$this->assertEquals($blockquote, (string) $xml->body->blockquote);

$xml = Xml::loadHtml($html, ['parseHuge' => true]);
$xml = html_entity_decode($xml->asXML(), ENT_NOQUOTES, 'UTF-8');
$this->assertEquals($html, $xml);
$this->assertTrue(isset($xml->body->p), 'Paragraph present');
$this->assertEquals($paragraph, (string) $xml->body->p);
$this->assertTrue(isset($xml->body->blockquote), 'Blockquote present');
$this->assertEquals($blockquote, (string) $xml->body->blockquote);
}

/**
Expand Down

0 comments on commit 9cddc7e

Please sign in to comment.