diff options
author | Technosophos <[email protected]> | 2013-04-17 14:35:11 -0500 |
---|---|---|
committer | Technosophos <[email protected]> | 2013-04-17 14:35:11 -0500 |
commit | 080a5b3105ba574d99215874eb26620c5f8e1907 (patch) | |
tree | ced25a26d468b9c28fb57fcf5436da8f325a0c95 /test | |
parent | 7ca281ea599de0ae016aada9da9a65da38db9760 (diff) | |
parent | fcbc66f9b8bd957b6878af0e0fed33457d47f072 (diff) |
Merge branch 'master' of github.com:technosophos/HTML5-PHP
Diffstat (limited to 'test')
-rw-r--r-- | test/HTML5/Serializer/SerializerTest.php (renamed from test/HTML5/SerializerTest.php) | 12 | ||||
-rw-r--r-- | test/HTML5/Serializer/TraverserTest.php | 78 |
2 files changed, 84 insertions, 6 deletions
diff --git a/test/HTML5/SerializerTest.php b/test/HTML5/Serializer/SerializerTest.php index ee8804e..a06fd50 100644 --- a/test/HTML5/SerializerTest.php +++ b/test/HTML5/Serializer/SerializerTest.php @@ -3,9 +3,9 @@ namespace HTML5\Tests; -use \HTML5\Serializer; +use \HTML5\Serializer\Serializer; -require_once 'TestCase.php'; +require_once __DIR__ . '/../TestCase.php'; /** * Test the Serializer. @@ -13,14 +13,14 @@ require_once 'TestCase.php'; * These tests are all dependent upon the parser. So if the parser * fails, the results of the serializer tests may not be conclusive. */ -class SerializerTest extends TestCase { +class SerializerTest extends \HTML5\Tests\TestCase { /** * Parse and serialize a string. */ protected function cycle($html) { $dom = \HTML5::parse($html); - $ser = new \HTML5\Serializer($dom, FALSE); + $ser = new Serializer($dom, FALSE); $out = $ser->saveHTML(); return $out; @@ -32,7 +32,7 @@ class SerializerTest extends TestCase { $dom = \HTML5::parse($html); $this->assertTrue($dom instanceof \DOMDocument, "Canary"); - $ser = new \HTML5\Serializer($dom, FALSE); + $ser = new Serializer($dom, FALSE); $out = $ser->saveHTML(); $this->assertTrue(count($out) >= count($html), 'Byte counts'); @@ -47,7 +47,7 @@ class SerializerTest extends TestCase { $dom = \HTML5::parse($html); $this->assertTrue($dom instanceof \DOMDocument, "Canary"); - $ser = new \HTML5\Serializer($dom, FALSE); + $ser = new Serializer($dom, FALSE); $out = fopen("php://temp", "w"); $ser->save($out); diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php new file mode 100644 index 0000000..0717a75 --- /dev/null +++ b/test/HTML5/Serializer/TraverserTest.php @@ -0,0 +1,78 @@ +<?php +namespace HTML5\Tests; + +use \HTML5\Serializer\Traverser; + +require_once __DIR__ . '/../TestCase.php'; + +class TraverserTest extends \HTML5\Tests\TestCase { + + /** + * 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('\HTML5\Serializer\Traverser'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; + } + + public function testIsBlock() { + $blocks = array('html', 'body', 'head', 'p', 'div', 'h1', 'h2', 'h3', 'h4', + 'h5', 'h6', 'title', 'script', 'link', 'meta', 'section', 'article', + 'table', 'tbody', 'tr', 'th', 'td', + //'form', + ); + + // Mocking the required input because there is no checking. + $t = new Traverser('', ''); + $method = $this->getProtectedMethod('isBlock'); + + foreach ($blocks as $block) { + $this->assertTrue($method->invoke($t, $block), 'Block test failed on: ' . $block); + + // Also test the uppercase version. + $this->assertTrue($method->invoke($t, strtoupper($block)), 'Block test failed on: ' . strtoupper($block)); + } + + $nonblocks = array('span', 'a', 'img'); + foreach ($nonblocks as $tag) { + $this->assertFalse($method->invoke($t, $tag), 'Block test failed on: ' . $tag); + + // Also test the uppercase version. + $this->assertFalse($method->invoke($t, strtoupper($tag)), 'Block test failed on: ' . strtoupper($tag)); + } + } + + public function testIsUnary() { + $elements = array( 'area', 'base', 'basefont', 'bgsound', 'br', 'col', + 'command', 'embed', 'frame', 'hr', 'img', + ); + + // Mocking the required input because there is no checking. + $t = new Traverser('', ''); + $method = $this->getProtectedMethod('isUnary'); + + foreach ($elements as $element) { + $this->assertTrue($method->invoke($t, $element), 'Unary test failed on: ' . $element); + + // Also test the uppercase version. + $this->assertTrue($method->invoke($t, strtoupper($element)), 'Unary test failed on: ' . strtoupper($element)); + } + + $nonblocks = array('span', 'a', 'div'); + foreach ($nonblocks as $tag) { + $this->assertFalse($method->invoke($t, $tag), 'Unary test failed on: ' . $tag); + + // Also test the uppercase version. + $this->assertFalse($method->invoke($t, strtoupper($tag)), 'Unary test failed on: ' . strtoupper($tag)); + } + } + +}
\ No newline at end of file |