File: Node_lookupNamespaceURI.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (95 lines) | stat: -rw-r--r-- 3,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--TEST--
Dom\Node::lookupNamespaceURI()
--EXTENSIONS--
dom
--FILE--
<?php

$dom = Dom\HTMLDocument::createFromString(<<<HTML
<!DOCTYPE html>
<html>
    <body>
        <svg xmlns="http://www.w3.org/2000/svg" height="1"></svg>
        <math></math>
    </body>
</html>
HTML);

$body = $dom->getElementsByTagName("body")[0];
$namespaceless = $body->appendChild($dom->createElementNS(NULL, "foo"));
$prefixed = $body->appendChild($dom->createElementNS("urn:a", "a:a"));

echo "--- Hardcoded prefixes ---\n";
var_dump($dom->lookupNamespaceURI("xml"));
var_dump($dom->lookupNamespaceURI("xmlns"));

echo "--- Default prefix ---\n";
var_dump($dom->lookupNamespaceURI(""));
var_dump($dom->lookupNamespaceURI(NULL));

echo "--- NULL namespace should propagate up ---\n";
var_dump($namespaceless->lookupNamespaceURI(""));
var_dump($namespaceless->lookupNamespaceURI(NULL));
var_dump($namespaceless->lookupNamespaceURI("a"));

echo "--- Prefixed element ---\n";
var_dump($prefixed->lookupNamespaceURI(""));
var_dump($prefixed->lookupNamespaceURI(NULL));
var_dump($prefixed->lookupNamespaceURI("a"));

echo "--- Prefixed element custom xmlns attribute should not change ns ---\n";
$prefixed->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "urn:another");
var_dump($prefixed->lookupNamespaceURI(""));
var_dump($prefixed->lookupNamespaceURI(NULL));
var_dump($prefixed->lookupNamespaceURI("a"));

echo "--- xmlns attribute defines new namespace ---\n";
$body->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "urn:another");
var_dump($body->lookupNamespaceURI(""));
var_dump($body->lookupNamespaceURI(NULL));
var_dump($body->lookupNamespaceURI("a"));

echo "--- empty xmlns attribute defines no new namespace ---\n";
$body->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "");
var_dump($body->lookupNamespaceURI(""));
var_dump($body->lookupNamespaceURI(NULL));
var_dump($body->lookupNamespaceURI("a"));

echo "--- lookup in empty document ---\n";
$dom = Dom\HTMLDocument::createEmpty();
var_dump($dom->lookupNamespaceURI(""));
var_dump($dom->lookupNamespaceURI(NULL));
var_dump($dom->lookupNamespaceURI("a"));

?>
--EXPECT--
--- Hardcoded prefixes ---
string(36) "http://www.w3.org/XML/1998/namespace"
string(29) "http://www.w3.org/2000/xmlns/"
--- Default prefix ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
--- NULL namespace should propagate up ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
NULL
--- Prefixed element ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
string(5) "urn:a"
--- Prefixed element custom xmlns attribute should not change ns ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
string(5) "urn:a"
--- xmlns attribute defines new namespace ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
string(11) "urn:another"
--- empty xmlns attribute defines no new namespace ---
string(28) "http://www.w3.org/1999/xhtml"
string(28) "http://www.w3.org/1999/xhtml"
NULL
--- lookup in empty document ---
NULL
NULL
NULL