Просмотр исходного кода

ZF-7771 move the 'edit' special GET logic up with the other special GET logic to fix a bug with the 'action' and 'id' param values for /edit requests

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18003 44c647ce-9c0f-0410-b52a-842ac1e357ba
lcrouch 16 лет назад
Родитель
Сommit
e7449ecdf8
2 измененных файлов с 26 добавлено и 6 удалено
  1. 4 6
      library/Zend/Rest/Route.php
  2. 22 0
      tests/Zend/Rest/RouteTest.php

+ 4 - 6
library/Zend/Rest/Route.php

@@ -149,8 +149,11 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
             $specialGetTarget = false;
             if ($pathElementCount && array_search($path[0], array('index', 'new')) > -1) {
                 $specialGetTarget = array_shift($path);
+            } elseif ($pathElementCount && $path[$pathElementCount-1] == 'edit') {
+                $specialGetTarget = 'edit';
+                $params['id'] = $path[$pathElementCount-2];
             } elseif ($pathElementCount == 1) {
-                 $params['id'] = array_shift($path);
+                $params['id'] = array_shift($path);
             } elseif ($pathElementCount == 0 || $pathElementCount > 1) {
                 $specialGetTarget = 'index';
             }
@@ -164,11 +167,6 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
                 }
             }
 
-            // Check for trailing "special get" URI
-            if (array_key_exists('edit', $params)) {
-                $specialGetTarget = 'edit';
-            }
-
             // Determine Action
             $requestMethod = strtolower($request->getMethod());
             if ($requestMethod != 'get') {

+ 22 - 0
tests/Zend/Rest/RouteTest.php

@@ -163,6 +163,19 @@ class Zend_Rest_RouteTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('zendframework', $values['id']);
     }
 
+    public function test_RESTfulApp_GET_project_edit()
+    {
+        $request = $this->_buildRequest('GET', '/project/zendframework/edit');
+        $values = $this->_invokeRouteMatch($request);
+         
+        $this->assertType('array', $values);
+        $this->assertTrue(isset($values['module']));
+        $this->assertEquals('default', $values['module']);
+        $this->assertEquals('project', $values['controller']);
+        $this->assertEquals('edit', $values['action']);
+        $this->assertEquals('zendframework', $values['id']);
+    }
+    
     public function test_RESTfulApp_PUT_user_byIdentifier()
     {
         $request = $this->_buildRequest('PUT', '/mod/user/lcrouch');
@@ -330,6 +343,15 @@ class Zend_Rest_RouteTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('index', $values['action']);
     }
 
+    public function test_RESTfulController_GET_default_controller_returns_false()
+    {
+        $request = $this->_buildRequest('GET', '/mod/index/index');
+        $config = array('mod'=>array('user'));
+        $values = $this->_invokeRouteMatch($request, $config);
+		
+        $this->assertFalse($values);
+    }
+    
     public function test_RESTfulController_GET_other_index_returns_false()
     {
         $request = $this->_buildRequest('GET', '/mod/project/index');