Skip to content

Commit dc9ed8a

Browse files
committed
Test Element::matches()
1 parent e1182ae commit dc9ed8a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ext/dom/tests/querySelector/test_utils.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@ function test_helper(DOM\ParentNode $dom, string $selector, bool $only_name = fa
1111
throw new Exception('Mismatch in querySelector and querySelectorAll');
1212
}
1313

14+
$list = [];
1415
foreach ($all as $node) {
16+
$list[] = $node;
17+
1518
if ($only_name) {
1619
echo $node->nodeName, "\n";
1720
continue;
1821
}
22+
1923
echo $dom->saveXML($node), "\n";
2024
}
25+
26+
// If the element is in the list, then it must match, otherwise it must not
27+
// This loops over all the elements in the document and checks them
28+
foreach ($dom->querySelectorAll('*') as $node) {
29+
if (in_array($node, $list, true) !== $node->matches($selector)) {
30+
var_dump($node, $selector, in_array($node, $list, true), $node->matches($selector));
31+
echo $dom->saveXML($node), "\n";
32+
throw new Exception('Bug in Element::matches()');
33+
}
34+
}
2135
}
2236

2337
function test_failure(DOM\ParentNode $dom, string $selector)

0 commit comments

Comments
 (0)