7
7
8
8
class QueryTest extends TestCase
9
9
{
10
- public function testSetCompiledException ()
10
+ /**
11
+ * @dataProvider compiledCssProvider
12
+ */
13
+ public function testCompileCssSelector ($ selector , $ xpath )
14
+ {
15
+ $ this ->assertEquals ($ xpath , Query::compile ($ selector ));
16
+ }
17
+
18
+ public function testCompileXpath ()
19
+ {
20
+ $ this ->assertEquals ('xpath-expression ' , Query::compile ('xpath-expression ' , Query::TYPE_XPATH ));
21
+ }
22
+
23
+ public function testSetCompiledInvalidArgument ()
11
24
{
12
25
$ this ->setExpectedException ('InvalidArgumentException ' );
13
26
@@ -29,12 +42,23 @@ public function testGetCompiled()
29
42
Query::setCompiled ([]);
30
43
31
44
$ selector = '.post h2 ' ;
32
- $ xpath = " //*[contains(concat(' ' , normalize-space(@class), ' ' ), ' post ')] " ;
45
+ $ xpath = ' //*[contains(concat(" " , normalize-space(@class), " " ), " post ")]//h2 ' ;
33
46
$ compiled = [$ selector => $ xpath ];
34
47
35
- $ xpath = Query::compile ($ selector );
36
- $ compiled = Query::getCompiled ();
48
+ Query::compile ($ selector );
37
49
38
50
$ this ->assertEquals ($ compiled , Query::getCompiled ());
39
51
}
52
+
53
+ public function compiledCssProvider ()
54
+ {
55
+ $ compiled = [
56
+ ['h2 ' , '//h2 ' ],
57
+ ['.post h2 ' , '//*[contains(concat(" ", normalize-space(@class), " "), " post ")]//h2 ' ],
58
+ ['.post, h2 ' , '//*[contains(concat(" ", normalize-space(@class), " "), " post ")]|//h2 ' ],
59
+ ['div#layout ' , "//div[@id='layout'] " ],
60
+ ];
61
+
62
+ return $ compiled ;
63
+ }
40
64
}
0 commit comments