1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
--TEST--
CSS Selectors - Combinators
--EXTENSIONS--
dom
--FILE--
<?php
require __DIR__ . '/test_utils.inc';
$dom = DOM\HTMLDocument::createFromString(<<<HTML
<!DOCTYPE html>
<html>
<body>
<p>First p</p>
<p>Second p</p>
<img src="1.png">
<div class="">
<p>Third p</p>
<img src="2.png">
<img src="3.png">
<div class="foo bar baz">
<p>Fourth p</p>
</div>
</div>
<article title="foo" class="bar">
<p class="bar">Fifth p</p>
</article>
<table border="1">
<colgroup>
<col class="selected">
</colgroup>
<tbody>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</tbody>
</table>
</body>
</html>
HTML);
test_helper($dom, 'nonsense');
test_helper($dom, 'p');
test_helper($dom, 'p, img');
test_helper($dom, 'body p');
test_helper($dom, 'body div p');
test_helper($dom, 'div > *');
test_helper($dom, 'div > p');
test_helper($dom, 'div > p + img');
test_helper($dom, 'div > p ~ img');
test_helper($dom, 'body > img');
test_helper($dom, 'div.bar.baz > p');
test_helper($dom, 'article[title].bar p');
try {
test_helper($dom, 'col.selected||td');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
--- Selector: nonsense ---
--- Selector: p ---
<p xmlns="http://www.w3.org/1999/xhtml">First p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Second p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
<p xmlns="http://www.w3.org/1999/xhtml" class="bar">Fifth p</p>
--- Selector: p, img ---
<p xmlns="http://www.w3.org/1999/xhtml">First p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Second p</p>
<img xmlns="http://www.w3.org/1999/xhtml" src="1.png" />
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<img xmlns="http://www.w3.org/1999/xhtml" src="2.png" />
<img xmlns="http://www.w3.org/1999/xhtml" src="3.png" />
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
<p xmlns="http://www.w3.org/1999/xhtml" class="bar">Fifth p</p>
--- Selector: body p ---
<p xmlns="http://www.w3.org/1999/xhtml">First p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Second p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
<p xmlns="http://www.w3.org/1999/xhtml" class="bar">Fifth p</p>
--- Selector: body div p ---
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
--- Selector: div > * ---
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<img xmlns="http://www.w3.org/1999/xhtml" src="2.png" />
<img xmlns="http://www.w3.org/1999/xhtml" src="3.png" />
<div xmlns="http://www.w3.org/1999/xhtml" class="foo bar baz">
<p>Fourth p</p>
</div>
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
--- Selector: div > p ---
<p xmlns="http://www.w3.org/1999/xhtml">Third p</p>
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
--- Selector: div > p + img ---
<img xmlns="http://www.w3.org/1999/xhtml" src="2.png" />
--- Selector: div > p ~ img ---
<img xmlns="http://www.w3.org/1999/xhtml" src="2.png" />
<img xmlns="http://www.w3.org/1999/xhtml" src="3.png" />
--- Selector: body > img ---
<img xmlns="http://www.w3.org/1999/xhtml" src="1.png" />
--- Selector: div.bar.baz > p ---
<p xmlns="http://www.w3.org/1999/xhtml">Fourth p</p>
--- Selector: article[title].bar p ---
<p xmlns="http://www.w3.org/1999/xhtml" class="bar">Fifth p</p>
--- Selector: col.selected||td ---
Dom\Document::querySelectorAll(): Argument #1 ($selectors) contains an unsupported selector
|