From 7ce303aec812129ab1805f40ad371cdc938355c9 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 27 May 2013 22:26:12 -0400 Subject: Added OutputRules tests. --- src/HTML5/Serializer/OutputRules.php | 1 - test/HTML5/Serializer/OutputRulesTest.php | 63 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) 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('foo'); + + $stream = fopen('php://temp', 'w'); + $t = new Traverser($dom, $stream, \HTML5::options()); + $o = new OutputRules($t, $stream, \HTML5::options()); + + $o->document($dom); + $this->assertEquals("\nfoo\n", stream_get_contents($stream, -1, 0)); + } + + + function testElement() { + $dom = \HTML5::loadHTML(' + + +
foo bar baz
+ + '); + + $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('
foo bar baz
', stream_get_contents($stream, -1, 0)); + } + + function testCData() { + $dom = \HTML5::loadHTML(' + + +
+ + '); + + $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('', stream_get_contents($stream, -1, 0)); + } + + function testComment() { + $dom = \HTML5::loadHTML(' + + +
+ + '); + + $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('', stream_get_contents($stream, -1, 0)); + } + function testText() { $dom = \HTML5::loadHTML(' -- cgit v1.2.3