summaryrefslogtreecommitdiff
path: root/test/HTML5/Serializer/TraverserTest.php
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-04-16 22:44:43 -0400
committerMatt Farina <[email protected]>2013-04-16 22:44:43 -0400
commit09de792de309eaaffe6153bf12e7a9b2bfe97f82 (patch)
treebd37b026611e9275810f7faf2fc7c1644f13f89c /test/HTML5/Serializer/TraverserTest.php
parentd1ea5d11c015bbad698af0dd300eb658fa532c5e (diff)
Converted the isBlock method to use a case insensitive mask and added tests for it.
Diffstat (limited to 'test/HTML5/Serializer/TraverserTest.php')
-rw-r--r--test/HTML5/Serializer/TraverserTest.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php
index c7e43d8..8638e22 100644
--- a/test/HTML5/Serializer/TraverserTest.php
+++ b/test/HTML5/Serializer/TraverserTest.php
@@ -7,4 +7,47 @@ 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: ' . $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: ' . $tag);
+ }
+ }
+
} \ No newline at end of file