summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-04-17 09:22:16 -0400
committerMatt Farina <[email protected]>2013-04-17 09:22:16 -0400
commitfcbc66f9b8bd957b6878af0e0fed33457d47f072 (patch)
tree96e9c8956a1f74e28522bf3f4a6d2259f89e4c28
parent09de792de309eaaffe6153bf12e7a9b2bfe97f82 (diff)
Rewrote isUnary testing and added tests.
-rw-r--r--src/HTML5/Serializer/Traverser.php22
-rw-r--r--test/HTML5/Serializer/TraverserTest.php29
2 files changed, 35 insertions, 16 deletions
diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php
index 34faf5c..6d5e805 100644
--- a/src/HTML5/Serializer/Traverser.php
+++ b/src/HTML5/Serializer/Traverser.php
@@ -33,19 +33,7 @@ class Traverser {
* input, keygen, link, meta, param, source, track or wbr element, then
* continue on to the next child node at this point.
*/
- static $unary_elements = array(
- 'area' => 1,
- 'base' => 1,
- 'basefont' => 1,
- 'bgsound' => 1,
- 'br' => 1,
- 'col' => 1,
- 'command' => 1,
- 'embed' => 1,
- 'frame' => 1,
- 'hr' => 1,
- 'img' => 1,
- );
+ static $unary_elements = 'area|base|basefont|bgsound|br|col|command|embed|frame|hr|img';
/** Namespaces that should be treated as "local" to HTML5. */
static $local_ns = array(
@@ -268,9 +256,15 @@ class Traverser {
/**
* Is an unary tag.
+ *
+ * @param string $name
+ * The name of the element to test.
+ *
+ * @return bool
+ * True if Unary and false otherwise.
*/
protected function isUnary($name) {
- return isset(self::$unary_elements[$name]);
+ return (bool)preg_match('/^(' . self::$unary_elements . ')$/i', $name);
}
/**
diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php
index 8638e22..0717a75 100644
--- a/test/HTML5/Serializer/TraverserTest.php
+++ b/test/HTML5/Serializer/TraverserTest.php
@@ -38,7 +38,7 @@ class TraverserTest extends \HTML5\Tests\TestCase {
$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);
+ $this->assertTrue($method->invoke($t, strtoupper($block)), 'Block test failed on: ' . strtoupper($block));
}
$nonblocks = array('span', 'a', 'img');
@@ -46,7 +46,32 @@ class TraverserTest extends \HTML5\Tests\TestCase {
$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);
+ $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));
}
}