Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into ValidatorMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
14 changes: 8 additions & 6 deletions src/Css2Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected static function _tokenize($expression)

// arbitrary attribute strict equality
$expression = preg_replace_callback(
'|\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
'|\[@?([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
function ($matches) {
return '[@' . strtolower($matches[1]) . "='" . $matches[2] . "']";
},
Expand Down Expand Up @@ -113,11 +113,13 @@ function ($matches) {
);

// Classes
$expression = preg_replace(
'|\.([a-z][a-z0-9_-]*)|i',
"[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]",
$expression
);
if(false === strpos($expression, "[@")) {
$expression = preg_replace(
'|\.([a-z][a-z0-9_-]*)|i',
"[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]",
$expression
);
}

/** ZF-9764 -- remove double asterisk */
$expression = str_replace('**', '*', $expression);
Expand Down
16 changes: 12 additions & 4 deletions test/Css2XpathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Dom
*/

namespace ZendTest\Dom;
Expand All @@ -15,9 +14,6 @@
/**
* Test class for Css2Xpath.
*
* @category Zend
* @package Zend_Dom
* @subpackage UnitTests
* @group Zend_Dom
*/
class Css2XpathTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -168,4 +164,16 @@ public function testIdSelectorWithLeadingAsterix()
$test = Css2Xpath::transform('*#id');
$this->assertEquals("//*[@id='id']", $test);
}

/**
* @group ZF-5310
*/
public function testCanTransformWithAttributeAndDot()
{
$test = Css2Xpath::transform('a[href="http://example.com"]');
$this->assertEquals("//a[@href='http://example.com']", $test);

$test = Css2Xpath::transform('a[@href="http://example.com"]');
$this->assertEquals("//a[@href='http://example.com']", $test);
}
}
4 changes: 0 additions & 4 deletions test/NodeListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Dom
*/

namespace ZendTest\Dom;

use Zend\Dom\NodeList;

/**
* @category Zend
* @package Zend_Dom
* @subpackage UnitTests
* @group Zend_Dom
*/
class NodeListTest extends \PHPUnit_Framework_TestCase
Expand Down
17 changes: 13 additions & 4 deletions test/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Dom
*/

namespace ZendTest\Dom;
Expand All @@ -17,9 +16,6 @@
/**
* Test class for Zend_Dom_Query.
*
* @category Zend
* @package Zend_Dom
* @subpackage UnitTests
* @group Zend_Dom
*/
class QueryTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -400,4 +396,17 @@ public function testOffsetUnset()

unset($results[2]);
}

/**
* @group ZF-5310
*/
public function testCssSelectorShouldFindNodesWhenMatchingAttributeValueWithDot()
{
$this->loadHtml();
$results = $this->query->execute('a[href="http://www.about.com"]');

$this->assertEquals(1, $results->count());
$this->assertEquals('About', $results[0]->nodeValue);

}
}
2 changes: 1 addition & 1 deletion test/_files/sample.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ul id="topnav">
<li class="current"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="http://www.about.com">About</a></li>
<li><a href="#">Misc</a></li>
<li><a href="#">Wiki</a></li>
</ul>
Expand Down

0 comments on commit 2e72915

Please sign in to comment.