629b561bfa97ea66251e4cd0a267229a7cfdf62d
[yaffs-website] / vendor / masterminds / html5 / test / HTML5 / ElementsTest.php
1 <?php
2 namespace Masterminds\HTML5\Tests;
3
4 use Masterminds\HTML5\Elements;
5
6 class ElementsTest extends TestCase
7 {
8
9     public $html5Elements = array(
10         "a",
11         "abbr",
12         "address",
13         "area",
14         "article",
15         "aside",
16         "audio",
17         "b",
18         "base",
19         "bdi",
20         "bdo",
21         "blockquote",
22         "body",
23         "br",
24         "button",
25         "canvas",
26         "caption",
27         "cite",
28         "code",
29         "col",
30         "colgroup",
31         "command",
32         // "data",
33         "datalist",
34         "dd",
35         "del",
36         "details",
37         "dfn",
38         "dialog",
39         "div",
40         "dl",
41         "dt",
42         "em",
43         "embed",
44         "fieldset",
45         "figcaption",
46         "figure",
47         "footer",
48         "form",
49         "h1",
50         "h2",
51         "h3",
52         "h4",
53         "h5",
54         "h6",
55         "head",
56         "header",
57         "hgroup",
58         "hr",
59         "html",
60         "i",
61         "iframe",
62         "img",
63         "input",
64         "ins",
65         "kbd",
66         "keygen",
67         "label",
68         "legend",
69         "li",
70         "link",
71         "map",
72         "mark",
73         "menu",
74         "meta",
75         "meter",
76         "nav",
77         "noscript",
78         "object",
79         "ol",
80         "optgroup",
81         "option",
82         "output",
83         "p",
84         "param",
85         "pre",
86         "progress",
87         "q",
88         "rp",
89         "rt",
90         "ruby",
91         "s",
92         "samp",
93         "script",
94         "section",
95         "select",
96         "small",
97         "source",
98         "span",
99         "strong",
100         "style",
101         "sub",
102         "summary",
103         "sup",
104         "table",
105         "tbody",
106         "td",
107         "textarea",
108         "tfoot",
109         "th",
110         "thead",
111         "time",
112         "title",
113         "tr",
114         "track",
115         "u",
116         "ul",
117         "var",
118         "video",
119         "wbr"
120     );
121
122     public $mathmlElements = array(
123         "maction",
124         "maligngroup",
125         "malignmark",
126         "math",
127         "menclose",
128         "merror",
129         "mfenced",
130         "mfrac",
131         "mglyph",
132         "mi",
133         "mlabeledtr",
134         "mlongdiv",
135         "mmultiscripts",
136         "mn",
137         "mo",
138         "mover",
139         "mpadded",
140         "mphantom",
141         "mroot",
142         "mrow",
143         "ms",
144         "mscarries",
145         "mscarry",
146         "msgroup",
147         "msline",
148         "mspace",
149         "msqrt",
150         "msrow",
151         "mstack",
152         "mstyle",
153         "msub",
154         "msup",
155         "msubsup",
156         "mtable",
157         "mtd",
158         "mtext",
159         "mtr",
160         "munder",
161         "munderover"
162     );
163
164     public $svgElements = array(
165         "a",
166         "altGlyph",
167         "altGlyphDef",
168         "altGlyphItem",
169         "animate",
170         "animateColor",
171         "animateMotion",
172         "animateTransform",
173         "circle",
174         "clipPath",
175         "color-profile",
176         "cursor",
177         "defs",
178         "desc",
179         "ellipse",
180         "feBlend",
181         "feColorMatrix",
182         "feComponentTransfer",
183         "feComposite",
184         "feConvolveMatrix",
185         "feDiffuseLighting",
186         "feDisplacementMap",
187         "feDistantLight",
188         "feFlood",
189         "feFuncA",
190         "feFuncB",
191         "feFuncG",
192         "feFuncR",
193         "feGaussianBlur",
194         "feImage",
195         "feMerge",
196         "feMergeNode",
197         "feMorphology",
198         "feOffset",
199         "fePointLight",
200         "feSpecularLighting",
201         "feSpotLight",
202         "feTile",
203         "feTurbulence",
204         "filter",
205         "font",
206         "font-face",
207         "font-face-format",
208         "font-face-name",
209         "font-face-src",
210         "font-face-uri",
211         "foreignObject",
212         "g",
213         "glyph",
214         "glyphRef",
215         "hkern",
216         "image",
217         "line",
218         "linearGradient",
219         "marker",
220         "mask",
221         "metadata",
222         "missing-glyph",
223         "mpath",
224         "path",
225         "pattern",
226         "polygon",
227         "polyline",
228         "radialGradient",
229         "rect",
230         "script",
231         "set",
232         "stop",
233         "style",
234         "svg",
235         "switch",
236         "symbol",
237         "text",
238         "textPath",
239         "title",
240         "tref",
241         "tspan",
242         "use",
243         "view",
244         "vkern"
245     );
246
247     public function testIsHtml5Element()
248     {
249         foreach ($this->html5Elements as $element) {
250             $this->assertTrue(Elements::isHtml5Element($element), 'html5 element test failed on: ' . $element);
251
252             $this->assertTrue(Elements::isHtml5Element(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element));
253         }
254
255         $nonhtml5 = array(
256             'foo',
257             'bar',
258             'baz'
259         );
260         foreach ($nonhtml5 as $element) {
261             $this->assertFalse(Elements::isHtml5Element($element), 'html5 element test failed on: ' . $element);
262
263             $this->assertFalse(Elements::isHtml5Element(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element));
264         }
265     }
266
267     public function testIsMathMLElement()
268     {
269         foreach ($this->mathmlElements as $element) {
270             $this->assertTrue(Elements::isMathMLElement($element), 'MathML element test failed on: ' . $element);
271
272             // MathML is case sensetitive so these should all fail.
273             $this->assertFalse(Elements::isMathMLElement(strtoupper($element)), 'MathML element test failed on: ' . strtoupper($element));
274         }
275
276         $nonMathML = array(
277             'foo',
278             'bar',
279             'baz'
280         );
281         foreach ($nonMathML as $element) {
282             $this->assertFalse(Elements::isMathMLElement($element), 'MathML element test failed on: ' . $element);
283         }
284     }
285
286     public function testIsSvgElement()
287     {
288         foreach ($this->svgElements as $element) {
289             $this->assertTrue(Elements::isSvgElement($element), 'SVG element test failed on: ' . $element);
290
291             // SVG is case sensetitive so these should all fail.
292             $this->assertFalse(Elements::isSvgElement(strtoupper($element)), 'SVG element test failed on: ' . strtoupper($element));
293         }
294
295         $nonSVG = array(
296             'foo',
297             'bar',
298             'baz'
299         );
300         foreach ($nonSVG as $element) {
301             $this->assertFalse(Elements::isSvgElement($element), 'SVG element test failed on: ' . $element);
302         }
303     }
304
305     public function testIsElement()
306     {
307         foreach ($this->html5Elements as $element) {
308             $this->assertTrue(Elements::isElement($element), 'html5 element test failed on: ' . $element);
309
310             $this->assertTrue(Elements::isElement(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element));
311         }
312
313         foreach ($this->mathmlElements as $element) {
314             $this->assertTrue(Elements::isElement($element), 'MathML element test failed on: ' . $element);
315
316             // MathML is case sensetitive so these should all fail.
317             $this->assertFalse(Elements::isElement(strtoupper($element)), 'MathML element test failed on: ' . strtoupper($element));
318         }
319
320         foreach ($this->svgElements as $element) {
321             $this->assertTrue(Elements::isElement($element), 'SVG element test failed on: ' . $element);
322
323             // SVG is case sensetitive so these should all fail. But, there is duplication
324             // html5 and SVG. Since html5 is case insensetitive we need to make sure
325             // it's not a html5 element first.
326             if (! in_array($element, $this->html5Elements)) {
327                 $this->assertFalse(Elements::isElement(strtoupper($element)), 'SVG element test failed on: ' . strtoupper($element));
328             }
329         }
330
331         $nonhtml5 = array(
332             'foo',
333             'bar',
334             'baz'
335         );
336         foreach ($nonhtml5 as $element) {
337             $this->assertFalse(Elements::isElement($element), 'html5 element test failed on: ' . $element);
338
339             $this->assertFalse(Elements::isElement(strtoupper($element)), 'html5 element test failed on: ' . strtoupper($element));
340         }
341     }
342
343     public function testElement()
344     {
345         foreach ($this->html5Elements as $element) {
346             $this->assertGreaterThan(0, Elements::element($element));
347         }
348         $nonhtml5 = array(
349             'foo',
350             'bar',
351             'baz'
352         );
353         foreach ($nonhtml5 as $element) {
354             $this->assertFalse(Elements::element($element));
355         }
356     }
357
358     public function testIsA()
359     {
360         $this->assertTrue(Elements::isA('script', Elements::KNOWN_ELEMENT));
361         $this->assertFalse(Elements::isA('scriptypoo', Elements::KNOWN_ELEMENT));
362         $this->assertTrue(Elements::isA('script', Elements::TEXT_RAW));
363         $this->assertFalse(Elements::isA('script', Elements::TEXT_RCDATA));
364
365         $voidElements = array(
366             'area',
367             'base',
368             'basefont',
369             'bgsound',
370             'br',
371             'col',
372             'command',
373             'embed',
374             'frame',
375             'hr',
376             'img'
377         );
378
379         foreach ($voidElements as $element) {
380             $this->assertTrue(Elements::isA($element, Elements::VOID_TAG), 'Void element test failed on: ' . $element);
381         }
382
383         $nonVoid = array(
384             'span',
385             'a',
386             'div'
387         );
388         foreach ($nonVoid as $tag) {
389             $this->assertFalse(Elements::isA($tag, Elements::VOID_TAG), 'Void element test failed on: ' . $tag);
390         }
391
392         $blockTags = array(
393             'address',
394             'article',
395             'aside',
396             'audio',
397             'blockquote',
398             'canvas',
399             'dd',
400             'div',
401             'dl',
402             'fieldset',
403             'figcaption',
404             'figure',
405             'footer',
406             'form',
407             'h1',
408             'h2',
409             'h3',
410             'h4',
411             'h5',
412             'h6',
413             'header',
414             'hgroup',
415             'hr',
416             'noscript',
417             'ol',
418             'output',
419             'p',
420             'pre',
421             'section',
422             'table',
423             'tfoot',
424             'ul',
425             'video'
426         );
427
428         foreach ($blockTags as $tag) {
429             $this->assertTrue(Elements::isA($tag, Elements::BLOCK_TAG), 'Block tag test failed on: ' . $tag);
430         }
431
432         $nonBlockTags = array(
433             'span',
434             'img',
435             'label'
436         );
437         foreach ($nonBlockTags as $tag) {
438             $this->assertFalse(Elements::isA($tag, Elements::BLOCK_TAG), 'Block tag test failed on: ' . $tag);
439         }
440     }
441
442     public function testNormalizeSvgElement()
443     {
444         $tests = array(
445             'foo' => 'foo',
446             'altglyph' => 'altGlyph',
447             'BAR' => 'bar',
448             'fespecularlighting' => 'feSpecularLighting',
449             'bAz' => 'baz',
450             'foreignobject' => 'foreignObject'
451         );
452
453         foreach ($tests as $input => $expected) {
454             $this->assertEquals($expected, Elements::normalizeSvgElement($input));
455         }
456     }
457
458     public function testNormalizeSvgAttribute()
459     {
460         $tests = array(
461             'foo' => 'foo',
462             'attributename' => 'attributeName',
463             'BAR' => 'bar',
464             'limitingconeangle' => 'limitingConeAngle',
465             'bAz' => 'baz',
466             'patterncontentunits' => 'patternContentUnits'
467         );
468
469         foreach ($tests as $input => $expected) {
470             $this->assertEquals($expected, Elements::normalizeSvgAttribute($input));
471         }
472     }
473
474     public function testNormalizeMathMlAttribute()
475     {
476         $tests = array(
477             'foo' => 'foo',
478             'definitionurl' => 'definitionURL',
479             'BAR' => 'bar'
480         );
481
482         foreach ($tests as $input => $expected) {
483             $this->assertEquals($expected, Elements::normalizeMathMlAttribute($input));
484         }
485     }
486 }