فهرست منبع

ZF-6281: only return strings from transform()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20479 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 سال پیش
والد
کامیت
ae999be625
2فایلهای تغییر یافته به همراه19 افزوده شده و 10 حذف شده
  1. 3 3
      library/Zend/Dom/Query/Css2Xpath.php
  2. 16 7
      tests/Zend/Dom/Query/Css2XpathTest.php

+ 3 - 3
library/Zend/Dom/Query/Css2Xpath.php

@@ -33,7 +33,7 @@ class Zend_Dom_Query_Css2Xpath
      * Transform CSS expression to XPath
      *
      * @param  string $path
-     * @return string|array
+     * @return string
      */
     public static function transform($path)
     {
@@ -49,7 +49,7 @@ class Zend_Dom_Query_Css2Xpath
                     $expressions = array_merge($expressions, $xpath);
                 }
             }
-            return $expressions;
+            return implode('|', $expressions);
         }
 
         $paths    = array('//');
@@ -80,7 +80,7 @@ class Zend_Dom_Query_Css2Xpath
         if (1 == count($paths)) {
             return $paths[0];
         }
-        return implode(' | ', $paths);
+        return implode('|', $paths);
     }
 
     /**

+ 16 - 7
tests/Zend/Dom/Query/Css2XpathTest.php

@@ -84,11 +84,15 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(is_string($test));
     }
 
+    /**
+     * @group ZF-6281
+     */
     public function testTransformShouldReturnMultiplePathsWhenExpressionContainsCommas()
     {
         $test = Zend_Dom_Query_Css2Xpath::transform('#foo, #bar');
-        $this->assertTrue(is_array($test));
-        $this->assertEquals(2, count($test));
+        $this->assertTrue(is_string($test));
+        $this->assertContains('|', $test);
+        $this->assertEquals(2, count(explode('|', $test)));
     }
 
     public function testTransformShouldRecognizeHashSymbolAsId()
@@ -106,7 +110,7 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
     public function testTransformShouldAssumeSpacesToIndicateRelativeXpathQueries()
     {
         $test = Zend_Dom_Query_Css2Xpath::transform('div#foo .bar');
-        $this->assertContains(' | ', $test);
+        $this->assertContains('|', $test);
         $expected = array(
             "//div[@id='foo']//*[contains(@class, ' bar ')]",
             "//div[@id='foo'][contains(@class, ' bar ')]",
@@ -122,16 +126,21 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
         $this->assertEquals("//div[@id='foo']/span", $test);
     }
 
+    /**
+     * @group ZF-6281
+     */
     public function testMultipleComplexCssSpecificationShouldTransformToExpectedXpath()
     {
         $test = Zend_Dom_Query_Css2Xpath::transform('div#foo span.bar, #bar li.baz a');
-        $this->assertTrue(is_array($test));
+        $this->assertTrue(is_string($test));
+        $this->assertContains('|', $test);
+        $actual   = explode('|', $test);
         $expected = array(
             "//div[@id='foo']//span[contains(@class, ' bar ')]",
             "//*[@id='bar']//li[contains(@class, ' baz ')]//a",
         );
-        $this->assertEquals(count($expected), count($test));
-        foreach ($test as $path) {
+        $this->assertEquals(count($expected), count($actual));
+        foreach ($actual as $path) {
             $this->assertContains($path, $expected);
         }
     }
@@ -139,7 +148,7 @@ class Zend_Dom_Query_Css2XpathTest extends PHPUnit_Framework_TestCase
     public function testClassNotationWithoutSpecifiedTagShouldResultInMultipleQueries()
     {
         $test = Zend_Dom_Query_Css2Xpath::transform('div.foo .bar a .baz span');
-        $this->assertContains(' | ', $test);
+        $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",