From d814e21b16f37a8895baa95e911f0502d1117879 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 24 Apr 2013 03:59:41 -0400 Subject: Added tests around the html element checking. --- src/HTML5/Elements.php | 23 +++++++- test/HTML5/ElementsTest.php | 140 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 test/HTML5/ElementsTest.php diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index a36f6ac..d437960 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -1,4 +1,5 @@ 1, "abbr" => 1, "address" => 1, @@ -34,6 +35,7 @@ class Elements { "col" => 1, "colgroup" => 1, "command" => 1, + //"data" => 1, // This is highly experimental and only part of the whatwg spec (not w3c). See https://developer.mozilla.org/en-US/docs/HTML/Element/data "datalist" => 1, "dd" => 1, "del" => 1, @@ -119,6 +121,23 @@ class Elements { "u" => 1, "ul" => 1, "var" => 1, + "video" => 1, "wbr" => 1, ); + + /** + * Test if an element is a valid html5 element. + * + * @param string $name + * The name of the element. + * + * @return bool + * True if a html5 element and false otherwise. + */ + public static function isHtml5Element($name) { + + // html5 element names are case insensetitive. Forcing lowercase for the check. + // Do we need this check or will all data passed here already be lowercase? + return isset(self::$elements[strtolower($name)]); + } } diff --git a/test/HTML5/ElementsTest.php b/test/HTML5/ElementsTest.php new file mode 100644 index 0000000..d3ba43b --- /dev/null +++ b/test/HTML5/ElementsTest.php @@ -0,0 +1,140 @@ +assertTrue(Elements::isHtml5Element($element), 'html5 element test failed on: ' . $element); + + $this->assertTrue(Elements::isHtml5Element(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element)); + } + + $nonhtml5 = array('foo', 'bar', 'baz'); + foreach ($nonhtml5 as $element) { + $this->assertFalse(Elements::isHtml5Element($element), 'html5 element test failed on: ' . $element); + + $this->assertFalse(Elements::isHtml5Element(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element)); + } + + + } + +} \ No newline at end of file -- cgit v1.2.3