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