Skip to content

Commit 1c43fda

Browse files
committed
Add regression tests with wrong output
1 parent 7eb3e9c commit 1c43fda

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

ext/dom/tests/bug80332_1.phpt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--TEST--
2+
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) - DOMNamedNodeMap variation
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument;
9+
10+
$doc->loadHTML('<span attr1="value1" attr2="value2"></span>');
11+
12+
$x = new DOMXPath($doc);
13+
$span = $x->query('//span')[0];
14+
15+
print "Node name: {$span->nodeName}\n";
16+
17+
function test($span, $key) {
18+
$key_formatted = match ($key) {
19+
false => 'false',
20+
true => 'true',
21+
null => 'null',
22+
default => is_string($key) ? "'$key'" : $key,
23+
};
24+
echo "Attribute [{$key_formatted}] name: ", $span->attributes[$key]->nodeName ?? '/', "\n";
25+
echo "Attribute [{$key_formatted}] value: ", $span->attributes[$key]->nodeValue ?? '/', "\n";
26+
echo "Attribute [{$key_formatted}] isset: ", isset($span->attributes[$key]) ? "yes" : "no", "\n";
27+
echo "\n";
28+
}
29+
30+
test($span, 0);
31+
test($span, false);
32+
test($span, true);
33+
test($span, null);
34+
test($span, 'attr2');
35+
// This one should fail because there is no 'hi' attribute
36+
test($span, 'hi');
37+
test($span, '0');
38+
test($span, '0.5');
39+
test($span, '1');
40+
// This one should fail because it's out of bounds
41+
test($span, '2147483647');
42+
43+
?>
44+
--EXPECT--
45+
Node name: span
46+
Attribute [0] name: attr1
47+
Attribute [0] value: value1
48+
Attribute [0] isset: yes
49+
50+
Attribute [false] name: attr1
51+
Attribute [false] value: value1
52+
Attribute [false] isset: yes
53+
54+
Attribute [true] name: attr2
55+
Attribute [true] value: value2
56+
Attribute [true] isset: yes
57+
58+
Attribute [null] name: attr1
59+
Attribute [null] value: value1
60+
Attribute [null] isset: yes
61+
62+
Attribute ['attr2'] name: attr1
63+
Attribute ['attr2'] value: value1
64+
Attribute ['attr2'] isset: yes
65+
66+
Attribute ['hi'] name: attr1
67+
Attribute ['hi'] value: value1
68+
Attribute ['hi'] isset: yes
69+
70+
Attribute ['0'] name: attr1
71+
Attribute ['0'] value: value1
72+
Attribute ['0'] isset: yes
73+
74+
Attribute ['0.5'] name: attr1
75+
Attribute ['0.5'] value: value1
76+
Attribute ['0.5'] isset: yes
77+
78+
Attribute ['1'] name: attr2
79+
Attribute ['1'] value: value2
80+
Attribute ['1'] isset: yes
81+
82+
Attribute ['2147483647'] name: /
83+
Attribute ['2147483647'] value: /
84+
Attribute ['2147483647'] isset: no

ext/dom/tests/bug80332_2.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) - DOMNodeList variation
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument;
9+
$doc->loadXML('<?xml version="1.0"?><span><strong id="1"/><strong id="2"/></span>');
10+
11+
$list = $doc->getElementsByTagName('strong');
12+
13+
function test($list, $key) {
14+
$key_formatted = match ($key) {
15+
false => 'false',
16+
true => 'true',
17+
null => 'null',
18+
default => is_string($key) ? "'$key'" : $key,
19+
};
20+
echo "list[$key_formatted] id attribute: ", $list[$key] ? $list[$key]->getAttribute('id') : '/', "\n";
21+
}
22+
23+
test($list, 0);
24+
test($list, false);
25+
test($list, true);
26+
test($list, null);
27+
test($list, '0');
28+
test($list, '0.5');
29+
test($list, '1');
30+
// These two should fail because there's no named lookup possible here
31+
test($list, 'attr2');
32+
test($list, 'hi');
33+
// This one should fail because it's out of bounds
34+
test($list, '2147483647');
35+
36+
?>
37+
--EXPECT--
38+
list[0] id attribute: 1
39+
list[false] id attribute: 1
40+
list[true] id attribute: 2
41+
list[null] id attribute: 1
42+
list['0'] id attribute: 1
43+
list['0.5'] id attribute: 1
44+
list['1'] id attribute: 2
45+
list['attr2'] id attribute: 1
46+
list['hi'] id attribute: 1
47+
list['2147483647'] id attribute: /

0 commit comments

Comments
 (0)