From 6f1871d3d957e308226522c902a63833f533db46 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 2 May 2013 11:43:27 -0500 Subject: Moved the traverser block checking code to use the mask on the elements class. --- src/HTML5/Serializer/Traverser.php | 41 +-------------------------------- test/HTML5/Serializer/TraverserTest.php | 21 ----------------- 2 files changed, 1 insertion(+), 61 deletions(-) diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php index 4a84b21..b8725f8 100644 --- a/src/HTML5/Serializer/Traverser.php +++ b/src/HTML5/Serializer/Traverser.php @@ -14,32 +14,6 @@ use \HTML5\Elements; */ class Traverser { - static $block_elements = array( - 'html' => 1, - 'body' => 1, - 'head' => 1, - 'p' => 1, - 'div' => 1, - 'h1' => 1, - 'h2' => 1, - 'h3' => 1, - 'h4' => 1, - 'h5' => 1, - 'h6' => 1, - 'title' => 1, - 'script' => 1, - 'link' => 1, - 'meta' => 1, - 'section' => 1, - 'article' => 1, - 'table' => 1, - 'tbody' => 1, - 'tr' => 1, - 'th' => 1, - 'td' => 1, - //'form' => 1, - ); - // TODO: Refactor this into an element mask. static $literal_elements = array( 'style' => 1, @@ -158,7 +132,7 @@ class Traverser { protected function element($ele) { $name = $ele->tagName; - $block = $this->pretty && $this->isBlock($name); + $block = $this->pretty && Elements::isA($name, Elements::BLOCK_TAG); // Per spec: // If the element has a declared namespace in the HTML, MathML or @@ -270,19 +244,6 @@ class Traverser { return $ret; } - /** - * Is block element. - * - * @param string $name - * The name of the element to test if a block level element - * - * @return bool - * If the element is block level or not. - */ - protected function isBlock($name) { - return isset(self::$block_elements[$name]); - } - /** * Is the element literal? * diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php index 56fa4e1..7162c6e 100644 --- a/test/HTML5/Serializer/TraverserTest.php +++ b/test/HTML5/Serializer/TraverserTest.php @@ -23,25 +23,4 @@ class TraverserTest extends \HTML5\Tests\TestCase { $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); - } - - $nonblocks = array('span', 'a', 'img'); - foreach ($nonblocks as $tag) { - $this->assertFalse($method->invoke($t, $tag), 'Block test failed on: ' . $tag); - } - } } \ No newline at end of file -- cgit v1.2.3