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. --- test/HTML5/Serializer/OutputRulesTest.php | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/HTML5') 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