1--TEST--
2Dom\Node::isDefaultNamespace()
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$dom = Dom\HTMLDocument::createFromString(<<<HTML
9<!DOCTYPE html>
10<html>
11    <body>
12        <svg xmlns="http://www.w3.org/2000/svg" height="1"></svg>
13        <math></math>
14    </body>
15</html>
16HTML);
17
18function dump($node) {
19    echo "svg NS: ";
20    var_dump($node->isDefaultNamespace('http://www.w3.org/2000/svg'));
21    echo "xhtml NS: ";
22    var_dump($node->isDefaultNamespace('http://www.w3.org/1999/xhtml'));
23    echo "mathml NS: ";
24    var_dump($node->isDefaultNamespace('http://www.w3.org/1998/Math/MathML'));
25    echo "empty NS: ";
26    var_dump($node->isDefaultNamespace(''));
27}
28
29echo "--- Document ---\n";
30dump($dom);
31echo "--- svg element ---\n";
32dump($dom->getElementsByTagName('svg')[0]);
33echo "--- math element ---\n";
34dump($dom->getElementsByTagName('math')[0]);
35echo "--- svg attribute ---\n";
36dump($dom->getElementsByTagName('svg')[0]->attributes[0]);
37echo "--- empty fragment ---\n";
38dump($dom->createDocumentFragment());
39echo "--- doctype ---\n";
40dump($dom->doctype);
41echo "--- detached attribute ---\n";
42dump($dom->createAttribute('foo'));
43echo "--- custom namespace with a prefix ---\n";
44var_dump($dom->createElementNS('urn:a', 'q:name')->isDefaultNamespace('urn:a'));
45echo "--- custom namespace with a prefix and with attributes ---\n";
46$element = $dom->createElementNS('urn:a', 'q:name');
47$element->setAttributeNS("urn:x", "x:foo", "");
48$element->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:q", "urn:test");
49$element->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "urn:test2");
50var_dump($element->isDefaultNamespace('urn:a'));
51var_dump($element->isDefaultNamespace('urn:test'));
52var_dump($element->isDefaultNamespace('urn:test2'));
53echo "--- custom namespace without a prefix ---\n";
54var_dump($dom->createElementNS('urn:a', 'name')->isDefaultNamespace('urn:a'));
55
56?>
57--EXPECT--
58--- Document ---
59svg NS: bool(false)
60xhtml NS: bool(true)
61mathml NS: bool(false)
62empty NS: bool(false)
63--- svg element ---
64svg NS: bool(true)
65xhtml NS: bool(false)
66mathml NS: bool(false)
67empty NS: bool(false)
68--- math element ---
69svg NS: bool(false)
70xhtml NS: bool(false)
71mathml NS: bool(true)
72empty NS: bool(false)
73--- svg attribute ---
74svg NS: bool(true)
75xhtml NS: bool(false)
76mathml NS: bool(false)
77empty NS: bool(false)
78--- empty fragment ---
79svg NS: bool(false)
80xhtml NS: bool(false)
81mathml NS: bool(false)
82empty NS: bool(true)
83--- doctype ---
84svg NS: bool(false)
85xhtml NS: bool(false)
86mathml NS: bool(false)
87empty NS: bool(true)
88--- detached attribute ---
89svg NS: bool(false)
90xhtml NS: bool(false)
91mathml NS: bool(false)
92empty NS: bool(true)
93--- custom namespace with a prefix ---
94bool(false)
95--- custom namespace with a prefix and with attributes ---
96bool(false)
97bool(false)
98bool(true)
99--- custom namespace without a prefix ---
100bool(true)
101