Ver Fonte

ZF-7658: addconfig problem with new default route

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18294 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan há 16 anos atrás
pai
commit
2850097999

+ 8 - 1
library/Zend/Controller/Router/Route/Regex.php

@@ -137,7 +137,14 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
                 }
                 $return[$index] = $values[$key];
             } elseif ($reversed) {
-                $index = (!is_int($key)) ? array_search($key, $this->_map, true) : $key;
+                $index = $key;
+                if (!is_int($key)) {
+                    if (isset($this->_map[$key]) && is_int($this->_map[$key])) {
+                        $index = $this->_map[$key];
+                    } else {
+                        $index = array_search($key, $this->_map, true);
+                    }
+                }
                 if (false !== $index) {
                     $return[$index] = $values[$key];
                 }

+ 41 - 0
tests/Zend/Controller/Router/Route/RegexTest.php

@@ -466,4 +466,45 @@ class Zend_Controller_Router_Route_RegexTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($url, $expectedUrl, 'Assembled url isn\'t encoded properly when using the encode parameter.');
     }
     
+    /**
+     * Allow using <lang>1</lang> instead of invalid <1>lang</1> for xml router
+     * config.
+     * 
+     * <zend-config>
+     *     <routes>
+     *         <page>
+     *             <type>Zend_Controller_Router_Route_Regex</type>
+     *             <route>([a-z]{2})/page/(.*)</route>
+     *             <defaults>
+     *                 <controller>index</controller>
+     *                 <action>showpage</action>
+     *             </defaults>
+     *             <map>
+     *                 <lang>1</lang>
+     *                 <title>2</title>
+     *             </map>
+     *             <reverse>%s/page/%s</reverse>
+     *         </page>
+     *     </routes>
+     * </zend-config>
+     * 
+     * 
+     * @group ZF-7658
+     */
+    public function testAssembleWithFlippedMappedVariables()
+    {
+        $route = new Zend_Controller_Router_Route_Regex(
+            '([a-z]{2})/page/(.*)',
+            array('controller' => 'index', 'action' => 'showpage'),
+            array('lang' => 1, 'title' => 2),
+            '%s/page/%s'
+        );
+        
+        $url = $route->assemble(array(
+            'lang'  => 'fi',
+            'title' => 'Suomi'
+        ), true, true);
+        
+        $this->assertEquals($url, 'fi/page/Suomi');
+    }
 }