summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/HTML5/Elements.php23
-rw-r--r--test/HTML5/ElementsTest.php140
2 files changed, 161 insertions, 2 deletions
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 @@
<?php
+namespace HTML5;
class Elements {
@@ -8,10 +9,10 @@ class Elements {
const OMIT_END = 0x0b;
/**
- * The HTML5 elements.
+ * The HTML5 elements as defined in http://dev.w3.org/html5/markup/elements.html.
* @var array
*/
- public static $properties = array(
+ public static $elements = array(
"a" => 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 @@
+<?php
+namespace HTML5\Tests;
+
+use \HTML5\Elements;
+
+require_once 'TestCase.php';
+
+class ElementsTest extends TestCase {
+
+ public function testIsHtml5Element() {
+ $html5 = array(
+ "a",
+ "abbr",
+ "address",
+ "area",
+ "article",
+ "aside",
+ "audio",
+ "b",
+ "base",
+ "bdi",
+ "bdo",
+ "blockquote",
+ "body",
+ "br",
+ "button",
+ "canvas",
+ "caption",
+ "cite",
+ "code",
+ "col",
+ "colgroup",
+ "command",
+ //"data",
+ "datalist",
+ "dd",
+ "del",
+ "details",
+ "dfn",
+ "dialog",
+ "div",
+ "dl",
+ "dt",
+ "em",
+ "embed",
+ "fieldset",
+ "figcaption",
+ "figure",
+ "footer",
+ "form",
+ "h1",
+ "h2",
+ "h3",
+ "h4",
+ "h5",
+ "h6",
+ "head",
+ "header",
+ "hgroup",
+ "hr",
+ "html",
+ "i",
+ "iframe",
+ "img",
+ "input",
+ "ins",
+ "kbd",
+ "keygen",
+ "label",
+ "legend",
+ "li",
+ "link",
+ "map",
+ "mark",
+ "menu",
+ "meta",
+ "meter",
+ "nav",
+ "noscript",
+ "object",
+ "ol",
+ "optgroup",
+ "option",
+ "output",
+ "p",
+ "param",
+ "pre",
+ "progress",
+ "q",
+ "rp",
+ "rt",
+ "ruby",
+ "s",
+ "samp",
+ "script",
+ "section",
+ "select",
+ "small",
+ "source",
+ "span",
+ "strong",
+ "style",
+ "sub",
+ "summary",
+ "sup",
+ "table",
+ "tbody",
+ "td",
+ "textarea",
+ "tfoot",
+ "th",
+ "thead",
+ "time",
+ "title",
+ "tr",
+ "track",
+ "u",
+ "ul",
+ "var",
+ "video",
+ "wbr",
+ );
+
+ foreach ($html5 as $element) {
+ $this->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