Skip to content

Commit b0fdd1a

Browse files
committed
Merge branch 'develop'
2 parents 9af2070 + 5c30b6d commit b0fdd1a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/DiDom/Query.php

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static function compile($expression, $type = self::TYPE_CSS)
4040

4141
if (array_key_exists($expression, static::$compiled)) {
4242
$paths[] = static::$compiled[$expression];
43+
continue;
4344
}
4445

4546
static::$compiled[$expression] = static::cssToXpath($expression);

tests/DiDom/QueryTest.php

+28-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@
77

88
class QueryTest extends TestCase
99
{
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()
1124
{
1225
$this->setExpectedException('InvalidArgumentException');
1326

@@ -29,12 +42,23 @@ public function testGetCompiled()
2942
Query::setCompiled([]);
3043

3144
$selector = '.post h2';
32-
$xpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' post ')]";
45+
$xpath = '//*[contains(concat(" ", normalize-space(@class), " "), " post ")]//h2';
3346
$compiled = [$selector => $xpath];
3447

35-
$xpath = Query::compile($selector);
36-
$compiled = Query::getCompiled();
48+
Query::compile($selector);
3749

3850
$this->assertEquals($compiled, Query::getCompiled());
3951
}
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+
}
4064
}

0 commit comments

Comments
 (0)