1--TEST-- 2Test DOM\Element::closest() method: legit cases 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$xml = <<<XML 9<root> 10 <a/> 11 <div class="foo" xml:id="div1"> 12 <div xml:id="div2"> 13 <div class="bar" xml:id="div3"/> 14 </div> 15 </div> 16</root> 17XML; 18 19$dom = DOM\XMLDocument::createFromString($xml); 20 21function test($el, $selector) { 22 echo "--- Selector: $selector ---\n"; 23 var_dump($el->closest($selector)?->getAttribute('xml:id')); 24} 25 26test($dom->getElementById('div3'), 'div'); 27test($dom->getElementById('div3'), '[class="foo"]'); 28test($dom->getElementById('div3'), ':not(root)'); 29test($dom->getElementById('div3'), ':not(div)'); 30test($dom->getElementById('div3'), 'a'); 31test($dom->getElementById('div3'), 'root :not(div[class])'); 32test($dom->getElementById('div3'), 'root > :not(div[class])'); 33 34?> 35--EXPECT-- 36--- Selector: div --- 37string(4) "div3" 38--- Selector: [class="foo"] --- 39string(4) "div1" 40--- Selector: :not(root) --- 41string(4) "div3" 42--- Selector: :not(div) --- 43NULL 44--- Selector: a --- 45NULL 46--- Selector: root :not(div[class]) --- 47string(4) "div2" 48--- Selector: root > :not(div[class]) --- 49NULL 50