--TEST--
HTMLCollection::namedItem() and dimension handling for named accesses
--EXTENSIONS--
dom
--FILE--
]>
1
2
2 with entity
3
4
5
without html ns
with html ns
XML;
$dom = Dom\XMLDocument::createFromString($xml);
function test($obj, $name) {
echo "--- Query \"$name\" ---\n";
var_dump($obj->namedItem($name)?->textContent);
var_dump($obj[$name]?->textContent);
var_dump(isset($obj[$name]));
// Search to check for dimension access consistency
$node = $obj[$name];
if ($node) {
$found = false;
for ($i = 0; $i < $obj->length && !$found; $i++) {
$found = $obj[$i] === $node;
}
if (!$found) {
throw new Error('inconsistency in dimension access');
}
}
}
test($dom->getElementsByTagName('node'), 'foo');
test($dom->getElementsByTagName('node'), '');
test($dom->getElementsByTagName('node'), 'does not exist');
test($dom->getElementsByTagName('node'), 'wrong');
test($dom->getElementsByTagName('node'), 'bar');
test($dom->getElementsByTagName('x'), 'foo');
test($dom->getElementsByTagName('x'), 'footest');
?>
--EXPECT--
--- Query "foo" ---
string(1) "5"
string(1) "5"
bool(true)
--- Query "" ---
NULL
NULL
bool(false)
--- Query "does not exist" ---
NULL
NULL
bool(false)
--- Query "wrong" ---
string(1) "4"
string(1) "4"
bool(true)
--- Query "bar" ---
string(12) "with html ns"
string(12) "with html ns"
bool(true)
--- Query "foo" ---
string(1) "2"
string(1) "2"
bool(true)
--- Query "footest" ---
string(13) "2 with entity"
string(13) "2 with entity"
bool(true)