diff options
author | Matt Farina <[email protected]> | 2013-05-27 22:26:12 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-05-27 22:26:12 -0400 |
commit | 7ce303aec812129ab1805f40ad371cdc938355c9 (patch) | |
tree | 9a9717631a84824e16de043e959c53cb7f2813c6 | |
parent | 06148348988730fe72699d6da2ff186bfa60ddf8 (diff) |
Added OutputRules tests.
-rw-r--r-- | src/HTML5/Serializer/OutputRules.php | 1 | ||||
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 63 |
2 files changed, 63 insertions, 1 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 65742e5..364f093 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -26,7 +26,6 @@ class OutputRules implements \HTML5\Serializer\RulesInterface { } $this->out = $output; - } public function document($dom) { diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index 3322e5a..a3fa3e8 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -47,6 +47,69 @@ class OutputRulesTest extends \HTML5\Tests\TestCase { return array($o, $stream); } + function testDocument() { + $dom = \HTML5::loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $o = new OutputRules($t, $stream, \HTML5::options()); + + $o->document($dom); + $this->assertEquals("<!DOCTYPE html>\n<html lang=\"en\"><body>foo</body></html>\n", stream_get_contents($stream, -1, 0)); + } + + + function testElement() { + $dom = \HTML5::loadHTML('<!doctype html> + <html lang="en"> + <body> + <div id="foo" class="bar baz">foo bar baz</div> + </body> + </html>'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $o = new OutputRules($t, $stream, \HTML5::options()); + + $list = $dom->getElementsByTagName('div'); + $o->element($list->item(0)); + $this->assertEquals('<div id="foo" class="bar baz">foo bar baz</div>', stream_get_contents($stream, -1, 0)); + } + + function testCData() { + $dom = \HTML5::loadHTML('<!doctype html> + <html lang="en"> + <body> + <div><![CDATA[bar]]></div> + </body> + </html>'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $o = new OutputRules($t, $stream, \HTML5::options()); + + $list = $dom->getElementsByTagName('div'); + $o->cdata($list->item(0)->childNodes->item(0)); + $this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, -1, 0)); + } + + function testComment() { + $dom = \HTML5::loadHTML('<!doctype html> + <html lang="en"> + <body> + <div><!-- foo --></div> + </body> + </html>'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $o = new OutputRules($t, $stream, \HTML5::options()); + + $list = $dom->getElementsByTagName('div'); + $o->comment($list->item(0)->childNodes->item(0)); + $this->assertEquals('<!-- foo -->', stream_get_contents($stream, -1, 0)); + } + function testText() { $dom = \HTML5::loadHTML('<!doctype html> <html lang="en"> |