diff options
author | Asmir Mustafic <[email protected]> | 2014-06-11 10:34:56 +0200 |
---|---|---|
committer | Asmir Mustafic <[email protected]> | 2014-06-11 10:34:56 +0200 |
commit | e49c45913b9cff66e3ca25a17e98604e18388e1e (patch) | |
tree | be24de17532fd4f0bbef1ac5d57766de1f8eb2de /test/HTML5/Serializer/OutputRulesTest.php | |
parent | d6940c3cc8eebd72627d42a0c0b3139f951716f4 (diff) |
PSR-2 code style
Diffstat (limited to 'test/HTML5/Serializer/OutputRulesTest.php')
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 604 |
1 files changed, 335 insertions, 269 deletions
diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index daae43a..27c66c4 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -3,11 +3,11 @@ namespace Masterminds\HTML5\Tests\Serializer; use Masterminds\HTML5\Serializer\OutputRules; use Masterminds\HTML5\Serializer\Traverser; -use Masterminds\HTML5\Parser; -class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { +class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase +{ - protected $markup = '<!doctype html> + protected $markup = '<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> @@ -17,69 +17,82 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { <p>This is a test.</p> </body> </html>'; - public function setUp() - { - $this->html5 = $this->getInstance(); - } - /** - * Using reflection we make a protected method accessible for testing. - * - * @param string $name - * The name of the method on the Traverser class to test. - * - * @return \ReflectionMethod - * \ReflectionMethod for the specified method - */ - function getProtectedMethod($name) { - $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\OutputRules'); - $method = $class->getMethod($name); - $method->setAccessible(true); - return $method; - } - - function getTraverserProtectedProperty($name) { - $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\Traverser'); - $property = $class->getProperty($name); - $property->setAccessible(true); - return $property; - } - - function getOutputRules($options = array()) { - $options = $options + $this->html5->getOptions(); - $stream = fopen('php://temp', 'w'); - $dom = $this->html5->loadHTML($this->markup); - $r = new OutputRules($stream, $options); - $t = new Traverser($dom, $stream, $r, $options); - - return array($r, $stream); - } - - function testDocument() { - $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); - - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $r->document($dom); - $expected = '<!DOCTYPE html>' . PHP_EOL . '<html lang="en"><body>foo</body></html>' . PHP_EOL; - $this->assertEquals($expected, stream_get_contents($stream, -1, 0)); - } - - function testDoctype() { - $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); - - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $m = $this->getProtectedMethod('doctype'); - $m->invoke($r, 'foo'); - $this->assertEquals("<!DOCTYPE html>" . PHP_EOL, stream_get_contents($stream, -1, 0)); - } - - function testElement() { - $dom = $this->html5->loadHTML('<!doctype html> + + public function setUp() + { + $this->html5 = $this->getInstance(); + } + + /** + * Using reflection we make a protected method accessible for testing. + * + * @param string $name + * The name of the method on the Traverser class to test. + * + * @return \ReflectionMethod \ReflectionMethod for the specified method + */ + public function getProtectedMethod($name) + { + $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\OutputRules'); + $method = $class->getMethod($name); + $method->setAccessible(true); + + return $method; + } + + public function getTraverserProtectedProperty($name) + { + $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\Traverser'); + $property = $class->getProperty($name); + $property->setAccessible(true); + + return $property; + } + + public function getOutputRules($options = array()) + { + $options = $options + $this->html5->getOptions(); + $stream = fopen('php://temp', 'w'); + $dom = $this->html5->loadHTML($this->markup); + $r = new OutputRules($stream, $options); + $t = new Traverser($dom, $stream, $r, $options); + + return array( + $r, + $stream + ); + } + + public function testDocument() + { + $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $r->document($dom); + $expected = '<!DOCTYPE html>' . PHP_EOL . '<html lang="en"><body>foo</body></html>' . PHP_EOL; + $this->assertEquals($expected, stream_get_contents($stream, - 1, 0)); + } + + public function testDoctype() + { + $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $m = $this->getProtectedMethod('doctype'); + $m->invoke($r, 'foo'); + $this->assertEquals("<!DOCTYPE html>" . PHP_EOL, stream_get_contents($stream, - 1, 0)); + } + + public function testElement() + { + $dom = $this->html5->loadHTML( + '<!doctype html> <html lang="en"> <body> <div id="foo" class="bar baz">foo bar baz</div> @@ -91,23 +104,25 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); - $r->element($list->item(0)); - $this->assertEquals('<div id="foo" class="bar baz">foo bar baz</div>', stream_get_contents($stream, -1, 0)); - } + $list = $dom->getElementsByTagName('div'); + $r->element($list->item(0)); + $this->assertEquals('<div id="foo" class="bar baz">foo bar baz</div>', stream_get_contents($stream, - 1, 0)); + } - function testElementWithScript() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testElementWithScript() + { + $dom = $this->html5->loadHTML( + '<!doctype html> <html lang="en"> <head> <script> var $jQ = jQuery.noConflict(); // Use jQuery via $jQ(...) - $jQ(document).ready(function(){ + $jQ(document).ready(function () { $jQ("#mktFrmSubmit").wrap("<div class=\'buttonSubmit\'></div>"); $jQ(".buttonSubmit").prepend("<span></span>"); }); @@ -118,24 +133,27 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $script = $dom->getElementsByTagName('script'); - $r->element($script->item(0)); - $this->assertEquals('<script> + $script = $dom->getElementsByTagName('script'); + $r->element($script->item(0)); + $this->assertEquals( + '<script> var $jQ = jQuery.noConflict(); // Use jQuery via $jQ(...) - $jQ(document).ready(function(){ + $jQ(document).ready(function () { $jQ("#mktFrmSubmit").wrap("<div class=\'buttonSubmit\'></div>"); $jQ(".buttonSubmit").prepend("<span></span>"); }); - </script>', stream_get_contents($stream, -1, 0)); - } + </script>', stream_get_contents($stream, - 1, 0)); + } - function testElementWithStyle() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testElementWithStyle() + { + $dom = $this->html5->loadHTML( + '<!doctype html> <html lang="en"> <head> <style> @@ -149,220 +167,265 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $style = $dom->getElementsByTagName('style'); - $r->element($style->item(0)); - $this->assertEquals('<style> + $style = $dom->getElementsByTagName('style'); + $r->element($style->item(0)); + $this->assertEquals('<style> body > .bar { display: none; } - </style>', stream_get_contents($stream, -1, 0)); - } + </style>', stream_get_contents($stream, - 1, 0)); + } - function testOpenTag() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testOpenTag() + { + $dom = $this->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'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); - $m = $this->getProtectedMethod('openTag'); - $m->invoke($r, $list->item(0)); - $this->assertEquals('<div id="foo" class="bar baz">', stream_get_contents($stream, -1, 0)); - } + $list = $dom->getElementsByTagName('div'); + $m = $this->getProtectedMethod('openTag'); + $m->invoke($r, $list->item(0)); + $this->assertEquals('<div id="foo" class="bar baz">', stream_get_contents($stream, - 1, 0)); + } - function testCData() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testCData() + { + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div><![CDATA[bar]]></div> </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); - $r->cdata($list->item(0)->childNodes->item(0)); - $this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, -1, 0)); + $list = $dom->getElementsByTagName('div'); + $r->cdata($list->item(0)->childNodes->item(0)); + $this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, - 1, 0)); - $dom = $this->html5->loadHTML('<!doctype html> + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div id="foo"></div> </body> </html>'); + $dom->getElementById('foo')->appendChild(new \DOMCdataSection("]]>Foo<[![CDATA test ]]>")); - $dom->getElementById('foo')->appendChild(new \DOMCdataSection("]]>Foo<[![CDATA test ]]>")); - - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); - $r->cdata($list->item(0)->childNodes->item(0)); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $list = $dom->getElementsByTagName('div'); + $r->cdata($list->item(0)->childNodes->item(0)); - $this->assertEquals('<![CDATA[]]]]><![CDATA[>Foo<[![CDATA test ]]]]><![CDATA[>]]>', stream_get_contents($stream, -1, 0)); - } + $this->assertEquals('<![CDATA[]]]]><![CDATA[>Foo<[![CDATA test ]]]]><![CDATA[>]]>', stream_get_contents($stream, - 1, 0)); + } - function testComment() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testComment() + { + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div><!-- foo --></div> </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $list = $dom->getElementsByTagName('div'); - $r->comment($list->item(0)->childNodes->item(0)); - $this->assertEquals('<!-- foo -->', stream_get_contents($stream, -1, 0)); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $list = $dom->getElementsByTagName('div'); + $r->comment($list->item(0)->childNodes->item(0)); + $this->assertEquals('<!-- foo -->', stream_get_contents($stream, - 1, 0)); - $dom = $this->html5->loadHTML('<!doctype html> + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div id="foo"></div> </body> </html>'); - $dom->getElementById('foo')->appendChild(new \DOMComment('<!-- --> --> Foo -->')); + $dom->getElementById('foo')->appendChild(new \DOMComment('<!-- --> --> Foo -->')); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); - $r->comment($list->item(0)->childNodes->item(0)); + $list = $dom->getElementsByTagName('div'); + $r->comment($list->item(0)->childNodes->item(0)); - // Could not find more definitive guidelines on what this should be. Went with - // what the HTML5 spec says and what \DOMDocument::saveXML() produces. - $this->assertEquals('<!--<!-- --> --> Foo -->-->', stream_get_contents($stream, -1, 0)); - } + // Could not find more definitive guidelines on what this should be. Went with + // what the HTML5 spec says and what \DOMDocument::saveXML() produces. + $this->assertEquals('<!--<!-- --> --> Foo -->-->', stream_get_contents($stream, - 1, 0)); + } - function testText() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testText() + { + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <head> <script>baz();</script> </head> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('script'); - $r->text($list->item(0)->childNodes->item(0)); - $this->assertEquals('baz();', stream_get_contents($stream, -1, 0)); + $list = $dom->getElementsByTagName('script'); + $r->text($list->item(0)->childNodes->item(0)); + $this->assertEquals('baz();', stream_get_contents($stream, - 1, 0)); - $dom = $this->html5->loadHTML('<!doctype html> + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <head id="foo"></head> </html>'); - $dom->getElementById('foo')->appendChild(new \DOMText('<script>alert("hi");</script>')); - - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $item = $dom->getElementById('foo'); - $r->text($item->firstChild); - $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, -1, 0)); - } - - function testNl() { - list($o, $s) = $this->getOutputRules(); - - $m = $this->getProtectedMethod('nl'); - $m->invoke($o); - $this->assertEquals(PHP_EOL, stream_get_contents($s, -1, 0)); - } - - function testWr() { - list($o, $s) = $this->getOutputRules(); - - $m = $this->getProtectedMethod('wr'); - $m->invoke($o, 'foo'); - $this->assertEquals('foo', stream_get_contents($s, -1, 0)); - } - - function getEncData(){ - return array( - array(FALSE, '&\'<>"', '&\'<>"', '&'<>"'), - array(FALSE, 'This + is. a < test', 'This + is. a < test', 'This + is. a < test'), - array(FALSE, '.+#', '.+#', '.+#'), - - array(TRUE, '.+#\'', '.+#\'', '.+#''), - array(TRUE, '&".<', '&".<', '&".<'), - array(TRUE, '&\'<>"', '&\'<>"', '&'<>"'), - array(TRUE, "\xc2\xa0\"'", ' "\'', ' "''), - ); - } - - /** - * Test basic encoding of text. - * @dataProvider getEncData - */ - function testEnc($isAttribute, $test, $expected, $expectedEncoded) { - - list($o, $s) = $this->getOutputRules(); - $m = $this->getProtectedMethod('enc'); - - $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); - - list($o, $s) = $this->getOutputRules(array('encode_entities' => TRUE)); - $m = $this->getProtectedMethod('enc'); - $this->assertEquals($expectedEncoded, $m->invoke($o, $test, $isAttribute)); - } - - /** - * Test basic encoding of text. - * @dataProvider getEncData - */ - function testEscape($isAttribute, $test, $expected, $expectedEncoded) { - - list($o, $s) = $this->getOutputRules(); - $m = $this->getProtectedMethod('escape'); - - $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); - } - - function testAttrs() { - $dom = $this->html5->loadHTML('<!doctype html> + $dom->getElementById('foo')->appendChild(new \DOMText('<script>alert("hi");</script>')); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $item = $dom->getElementById('foo'); + $r->text($item->firstChild); + $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, - 1, 0)); + } + + public function testNl() + { + list ($o, $s) = $this->getOutputRules(); + + $m = $this->getProtectedMethod('nl'); + $m->invoke($o); + $this->assertEquals(PHP_EOL, stream_get_contents($s, - 1, 0)); + } + + public function testWr() + { + list ($o, $s) = $this->getOutputRules(); + + $m = $this->getProtectedMethod('wr'); + $m->invoke($o, 'foo'); + $this->assertEquals('foo', stream_get_contents($s, - 1, 0)); + } + + public function getEncData() + { + return array( + array( + FALSE, + '&\'<>"', + '&\'<>"', + '&'<>"' + ), + array( + FALSE, + 'This + is. a < test', + 'This + is. a < test', + 'This + is. a < test' + ), + array( + FALSE, + '.+#', + '.+#', + '.+#' + ), + + array( + TRUE, + '.+#\'', + '.+#\'', + '.+#'' + ), + array( + TRUE, + '&".<', + '&".<', + '&".<' + ), + array( + TRUE, + '&\'<>"', + '&\'<>"', + '&'<>"' + ), + array( + TRUE, + "\xc2\xa0\"'", + ' "\'', + ' "'' + ) + ); + } + + /** + * Test basic encoding of text. + * @dataProvider getEncData + */ + public function testEnc($isAttribute, $test, $expected, $expectedEncoded) + { + list ($o, $s) = $this->getOutputRules(); + $m = $this->getProtectedMethod('enc'); + + $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); + + list ($o, $s) = $this->getOutputRules(array( + 'encode_entities' => TRUE + )); + $m = $this->getProtectedMethod('enc'); + $this->assertEquals($expectedEncoded, $m->invoke($o, $test, $isAttribute)); + } + + /** + * Test basic encoding of text. + * @dataProvider getEncData + */ + public function testEscape($isAttribute, $test, $expected, $expectedEncoded) + { + list ($o, $s) = $this->getOutputRules(); + $m = $this->getProtectedMethod('escape'); + + $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); + } + + public function testAttrs() + { + $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div id="foo" class="bar baz" disabled>foo bar baz</div> </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $list = $dom->getElementsByTagName('div'); + $list = $dom->getElementsByTagName('div'); - $m = $this->getProtectedMethod('attrs'); - $m->invoke($r, $list->item(0)); + $m = $this->getProtectedMethod('attrs'); + $m->invoke($r, $list->item(0)); - $content = stream_get_contents($stream, -1, 0); - $this->assertEquals(' id="foo" class="bar baz" disabled', $content); - } + $content = stream_get_contents($stream, - 1, 0); + $this->assertEquals(' id="foo" class="bar baz" disabled', $content); + } - function testSvg() { - $dom = $this->html5->loadHTML('<!doctype html> + public function testSvg() + { + $dom = $this->html5->loadHTML( + '<!doctype html> <html lang="en"> <body> <div id="foo" class="bar baz">foo bar baz</div> @@ -377,20 +440,22 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $list = $dom->getElementsByTagName('svg'); - $r->element($list->item(0)); - $contents = stream_get_contents($stream, -1, 0); - $this->assertRegExp('|<svg width="150" height="100" viewBox="0 0 3 2">|', $contents); - $this->assertRegExp('|<rect width="1" height="2" x="0" fill="#008d46" />|', $contents); - $this->assertRegExp('|<rect id="Bar" x="300" y="100" width="300" height="100" fill="rgb\(255,255,0\)">|', $contents); - } - - function testMath() { - $dom = $this->html5->loadHTML('<!doctype html> + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $list = $dom->getElementsByTagName('svg'); + $r->element($list->item(0)); + $contents = stream_get_contents($stream, - 1, 0); + $this->assertRegExp('|<svg width="150" height="100" viewBox="0 0 3 2">|', $contents); + $this->assertRegExp('|<rect width="1" height="2" x="0" fill="#008d46" />|', $contents); + $this->assertRegExp('|<rect id="Bar" x="300" y="100" width="300" height="100" fill="rgb\(255,255,0\)">|', $contents); + } + + public function testMath() + { + $dom = $this->html5->loadHTML( + '<!doctype html> <html lang="en"> <body> <div id="foo" class="bar baz">foo bar baz</div> @@ -404,26 +469,27 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { </body> </html>'); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $list = $dom->getElementsByTagName('math'); - $r->element($list->item(0)); - $content = stream_get_contents($stream, -1, 0); - $this->assertRegExp('|<math>|', $content); - $this->assertRegExp('|<csymbol definitionURL="http://www.example.com/mathops/multiops.html#plusminus">|', $content); - } - - function testProcessorInstruction() { - $dom = $this->html5->loadHTMLFragment('<?foo bar ?>'); - - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - - $r->processorInstruction($dom->firstChild); - $content = stream_get_contents($stream, -1, 0); - $this->assertRegExp('|<\?foo bar \?>|', $content); - } + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $list = $dom->getElementsByTagName('math'); + $r->element($list->item(0)); + $content = stream_get_contents($stream, - 1, 0); + $this->assertRegExp('|<math>|', $content); + $this->assertRegExp('|<csymbol definitionURL="http://www.example.com/mathops/multiops.html#plusminus">|', $content); + } + + public function testProcessorInstruction() + { + $dom = $this->html5->loadHTMLFragment('<?foo bar ?>'); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $r->processorInstruction($dom->firstChild); + $content = stream_get_contents($stream, - 1, 0); + $this->assertRegExp('|<\?foo bar \?>|', $content); + } } |