|
|
@@ -20,18 +20,11 @@
|
|
|
* @version $Id$
|
|
|
*/
|
|
|
|
|
|
-// Call Zend_Dom_Query_Css2XpathTest::main() if this source file is executed directly.
|
|
|
-if (!defined("PHPUnit_MAIN_METHOD")) {
|
|
|
- define("PHPUnit_MAIN_METHOD", "Zend_Dom_Query_Css2XpathTest::main");
|
|
|
-}
|
|
|
-
|
|
|
require_once dirname(__FILE__) . '/../../../TestHelper.php';
|
|
|
-
|
|
|
-/** Zend_Dom_Query_Css2Xpath */
|
|
|
require_once 'Zend/Dom/Query/Css2Xpath.php';
|
|
|
|
|
|
/**
|
|
|
- * Test class for Zend_Dom_Query_Css2Xpath.
|
|
|
+ * Test class for Css2Xpath.
|
|
|
*
|
|
|
* @category Zend
|
|
|
* @package Zend_Dom
|
|
|
@@ -42,37 +35,6 @@ require_once 'Zend/Dom/Query/Css2Xpath.php';
|
|
|
*/
|
|
|
class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
- /**
|
|
|
- * Runs the test methods of this class.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public static function main()
|
|
|
- {
|
|
|
- $suite = new PHPUnit_Framework_TestSuite("Zend_Dom_Query_Css2XpathTest");
|
|
|
- $result = PHPUnit_TextUI_TestRunner::run($suite);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets up the fixture, for example, open a network connection.
|
|
|
- * This method is called before a test is executed.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function setUp()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Tears down the fixture, for example, close a network connection.
|
|
|
- * This method is called after a test is executed.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function tearDown()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
public function testTransformShouldBeCalledStatically()
|
|
|
{
|
|
|
Zend_Dom_Query_Css2Xpath::transform('');
|
|
|
@@ -104,7 +66,7 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
public function testTransformShouldRecognizeDotSymbolAsClass()
|
|
|
{
|
|
|
$test = Zend_Dom_Query_Css2Xpath::transform('.foo');
|
|
|
- $this->assertEquals("//*[contains(@class, ' foo ')]", $test);
|
|
|
+ $this->assertEquals("//*[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", $test);
|
|
|
}
|
|
|
|
|
|
public function testTransformShouldAssumeSpacesToIndicateRelativeXpathQueries()
|
|
|
@@ -112,8 +74,8 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
$test = Zend_Dom_Query_Css2Xpath::transform('div#foo .bar');
|
|
|
$this->assertContains('|', $test);
|
|
|
$expected = array(
|
|
|
- "//div[@id='foo']//*[contains(@class, ' bar ')]",
|
|
|
- "//div[@id='foo'][contains(@class, ' bar ')]",
|
|
|
+ "//div[@id='foo']//*[contains(concat(' ', normalize-space(@class), ' '), ' bar ')]",
|
|
|
+ "//div[@id='foo'][contains(concat(' ', normalize-space(@class), ' '), ' bar ')]",
|
|
|
);
|
|
|
foreach ($expected as $path) {
|
|
|
$this->assertContains($path, $test);
|
|
|
@@ -136,8 +98,8 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
$this->assertContains('|', $test);
|
|
|
$actual = explode('|', $test);
|
|
|
$expected = array(
|
|
|
- "//div[@id='foo']//span[contains(@class, ' bar ')]",
|
|
|
- "//*[@id='bar']//li[contains(@class, ' baz ')]//a",
|
|
|
+ "//div[@id='foo']//span[contains(concat(' ', normalize-space(@class), ' '), ' bar ')]",
|
|
|
+ "//*[@id='bar']//li[contains(concat(' ', normalize-space(@class), ' '), ' baz ')]//a",
|
|
|
);
|
|
|
$this->assertEquals(count($expected), count($actual));
|
|
|
foreach ($actual as $path) {
|
|
|
@@ -150,10 +112,10 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
$test = Zend_Dom_Query_Css2Xpath::transform('div.foo .bar a .baz span');
|
|
|
$this->assertContains('|', $test);
|
|
|
$segments = array(
|
|
|
- "//div[contains(@class, ' foo ')]//*[contains(@class, ' bar ')]//a//*[contains(@class, ' baz ')]//span",
|
|
|
- "//div[contains(@class, ' foo ')]//*[contains(@class, ' bar ')]//a[contains(@class, ' baz ')]//span",
|
|
|
- "//div[contains(@class, ' foo ')][contains(@class, ' bar ')]//a//*[contains(@class, ' baz ')]//span",
|
|
|
- "//div[contains(@class, ' foo ')][contains(@class, ' bar ')]//a[contains(@class, ' baz ')]//span",
|
|
|
+ "//div[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]//*[contains(concat(' ', normalize-space(@class), ' '), ' bar ')]//a//*[contains(concat(' ', normalize-space(@class), ' '), ' baz ')]//span",
|
|
|
+ "//div[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]//*[contains(concat(' ', normalize-space(@class), ' '), ' bar ')]//a[contains(concat(' ', normalize-space(@class), ' '), ' baz ')]//span",
|
|
|
+ "//div[contains(concat(' ', normalize-space(@class), ' '), ' foo ')][contains(concat(' ', normalize-space(@class), ' '), ' bar ')]//a//*[contains(concat(' ', normalize-space(@class), ' '), ' baz ')]//span",
|
|
|
+ "//div[contains(concat(' ', normalize-space(@class), ' '), ' foo ')][contains(concat(' ', normalize-space(@class), ' '), ' bar ')]//a[contains(concat(' ', normalize-space(@class), ' '), ' baz ')]//span",
|
|
|
);
|
|
|
foreach ($segments as $xpath) {
|
|
|
$this->assertContains($xpath, $test);
|
|
|
@@ -175,7 +137,7 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
public function testShouldAllowContentSubSelectionOfArbitraryAttributes()
|
|
|
{
|
|
|
$test = Zend_Dom_Query_Css2Xpath::transform('div[foo~="bar"]');
|
|
|
- $this->assertEquals("//div[contains(@foo, ' bar ')]", $test);
|
|
|
+ $this->assertEquals("//div[contains(concat(' ', normalize-space(@foo), ' '), ' bar ')]", $test);
|
|
|
}
|
|
|
|
|
|
public function testShouldAllowContentMatchingOfArbitraryAttributes()
|
|
|
@@ -201,9 +163,22 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
|
|
|
$test = Zend_Dom_Query_Css2Xpath::transform('child > leaf');
|
|
|
$this->assertEquals("//child/leaf", $test);
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-// Call Zend_Dom_Query_Css2XpathTest::main() if this source file is executed directly.
|
|
|
-if (PHPUnit_MAIN_METHOD == "Zend_Dom_Query_Css2XpathTest::main") {
|
|
|
- Zend_Dom_Query_Css2XpathTest::main();
|
|
|
+ /**
|
|
|
+ * @group ZF-9764
|
|
|
+ */
|
|
|
+ public function testIdSelectorWithAttribute()
|
|
|
+ {
|
|
|
+ $test = Zend_Dom_Query_Css2Xpath::transform('#id[attribute="value"]');
|
|
|
+ $this->assertEquals("//*[@id='id'][@attribute='value']", $test);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9764
|
|
|
+ */
|
|
|
+ public function testIdSelectorWithLeadingAsterix()
|
|
|
+ {
|
|
|
+ $test = Zend_Dom_Query_Css2Xpath::transform('*#id');
|
|
|
+ $this->assertEquals("//*[@id='id']", $test);
|
|
|
+ }
|
|
|
}
|