Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Imangazaliev committed Oct 15, 2015
2 parents 9af2070 + 5c30b6d commit b0fdd1a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/DiDom/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function compile($expression, $type = self::TYPE_CSS)

if (array_key_exists($expression, static::$compiled)) {
$paths[] = static::$compiled[$expression];
continue;
}

static::$compiled[$expression] = static::cssToXpath($expression);
Expand Down
32 changes: 28 additions & 4 deletions tests/DiDom/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@

class QueryTest extends TestCase
{
public function testSetCompiledException()
/**
* @dataProvider compiledCssProvider
*/
public function testCompileCssSelector($selector, $xpath)
{
$this->assertEquals($xpath, Query::compile($selector));
}

public function testCompileXpath()
{
$this->assertEquals('xpath-expression', Query::compile('xpath-expression', Query::TYPE_XPATH));
}

public function testSetCompiledInvalidArgument()
{
$this->setExpectedException('InvalidArgumentException');

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

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

$xpath = Query::compile($selector);
$compiled = Query::getCompiled();
Query::compile($selector);

$this->assertEquals($compiled, Query::getCompiled());
}

public function compiledCssProvider()
{
$compiled = [
['h2', '//h2'],
['.post h2', '//*[contains(concat(" ", normalize-space(@class), " "), " post ")]//h2'],
['.post, h2', '//*[contains(concat(" ", normalize-space(@class), " "), " post ")]|//h2'],
['div#layout', "//div[@id='layout']"],
];

return $compiled;
}
}

0 comments on commit b0fdd1a

Please sign in to comment.