1--TEST--
2Dom\Node::lookupNamespaceURI()
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
18$body = $dom->getElementsByTagName("body")[0];
19$namespaceless = $body->appendChild($dom->createElementNS(NULL, "foo"));
20$prefixed = $body->appendChild($dom->createElementNS("urn:a", "a:a"));
21
22echo "--- Hardcoded prefixes ---\n";
23var_dump($dom->lookupNamespaceURI("xml"));
24var_dump($dom->lookupNamespaceURI("xmlns"));
25
26echo "--- Default prefix ---\n";
27var_dump($dom->lookupNamespaceURI(""));
28var_dump($dom->lookupNamespaceURI(NULL));
29
30echo "--- NULL namespace should propagate up ---\n";
31var_dump($namespaceless->lookupNamespaceURI(""));
32var_dump($namespaceless->lookupNamespaceURI(NULL));
33var_dump($namespaceless->lookupNamespaceURI("a"));
34
35echo "--- Prefixed element ---\n";
36var_dump($prefixed->lookupNamespaceURI(""));
37var_dump($prefixed->lookupNamespaceURI(NULL));
38var_dump($prefixed->lookupNamespaceURI("a"));
39
40echo "--- Prefixed element custom xmlns attribute should not change ns ---\n";
41$prefixed->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "urn:another");
42var_dump($prefixed->lookupNamespaceURI(""));
43var_dump($prefixed->lookupNamespaceURI(NULL));
44var_dump($prefixed->lookupNamespaceURI("a"));
45
46echo "--- xmlns attribute defines new namespace ---\n";
47$body->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "urn:another");
48var_dump($body->lookupNamespaceURI(""));
49var_dump($body->lookupNamespaceURI(NULL));
50var_dump($body->lookupNamespaceURI("a"));
51
52echo "--- empty xmlns attribute defines no new namespace ---\n";
53$body->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "");
54var_dump($body->lookupNamespaceURI(""));
55var_dump($body->lookupNamespaceURI(NULL));
56var_dump($body->lookupNamespaceURI("a"));
57
58echo "--- lookup in empty document ---\n";
59$dom = Dom\HTMLDocument::createEmpty();
60var_dump($dom->lookupNamespaceURI(""));
61var_dump($dom->lookupNamespaceURI(NULL));
62var_dump($dom->lookupNamespaceURI("a"));
63
64?>
65--EXPECT--
66--- Hardcoded prefixes ---
67string(36) "http://www.w3.org/XML/1998/namespace"
68string(29) "http://www.w3.org/2000/xmlns/"
69--- Default prefix ---
70string(28) "http://www.w3.org/1999/xhtml"
71string(28) "http://www.w3.org/1999/xhtml"
72--- NULL namespace should propagate up ---
73string(28) "http://www.w3.org/1999/xhtml"
74string(28) "http://www.w3.org/1999/xhtml"
75NULL
76--- Prefixed element ---
77string(28) "http://www.w3.org/1999/xhtml"
78string(28) "http://www.w3.org/1999/xhtml"
79string(5) "urn:a"
80--- Prefixed element custom xmlns attribute should not change ns ---
81string(28) "http://www.w3.org/1999/xhtml"
82string(28) "http://www.w3.org/1999/xhtml"
83string(5) "urn:a"
84--- xmlns attribute defines new namespace ---
85string(28) "http://www.w3.org/1999/xhtml"
86string(28) "http://www.w3.org/1999/xhtml"
87string(11) "urn:another"
88--- empty xmlns attribute defines no new namespace ---
89string(28) "http://www.w3.org/1999/xhtml"
90string(28) "http://www.w3.org/1999/xhtml"
91NULL
92--- lookup in empty document ---
93NULL
94NULL
95NULL
96