1<?php 2 3function test_helper(DOM\ParentNode $dom, string $selector, bool $only_name = false) 4{ 5 echo "--- Selector: $selector ---\n"; 6 7 $all = $dom->querySelectorAll($selector); 8 $single = $dom->querySelector($selector); 9 10 if ((count($all) === 0 && $single !== null) || ($all[0] !== $single)) { 11 throw new Exception('Mismatch in querySelector and querySelectorAll'); 12 } 13 14 $list = []; 15 foreach ($all as $node) { 16 $list[] = $node; 17 18 if ($only_name) { 19 echo $node->nodeName, "\n"; 20 continue; 21 } 22 23 echo $dom->saveXML($node), "\n"; 24 } 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 } 35} 36 37function test_failure(DOM\ParentNode $dom, string $selector) 38{ 39 echo "--- Selector: $selector ---\n"; 40 41 try { 42 var_dump(count($dom->querySelectorAll($selector))); 43 } catch (DOMException $e) { 44 echo "Code ", $e->getCode(), " ", $e->getMessage(), "\n"; 45 } 46} 47