Browse Source

Merge pull request #6481 from robbertnoordzij/fix-integrationtest-get

Fix for query parameters in integration test
Mark Story 11 years ago
parent
commit
25092c8355

+ 22 - 1
src/TestSuite/IntegrationTestCase.php

@@ -350,11 +350,13 @@ abstract class IntegrationTestCase extends TestCase
         $session = Session::create($sessionConfig);
         $session->write($this->_session);
 
+        list ($url, $query) = $this->_url($url);
         $props = [
-            'url' => Router::url($url),
+            'url' => $url,
             'post' => $data,
             'cookies' => $this->_cookie,
             'session' => $session,
+            'query' => $query
         ];
         $env = [];
         if (isset($this->_request['headers'])) {
@@ -370,6 +372,25 @@ abstract class IntegrationTestCase extends TestCase
     }
 
     /**
+     * Creates a valid request url and parameter array more like Request::_url()
+     *
+     * @param string|array $url The URL
+     * @return array Qualified URL and the query parameters
+     */
+    protected function _url($url)
+    {
+        $url = Router::url($url);
+        $query = [];
+
+        if (strpos($url, '?') !== false) {
+            list($url, $parameters) = explode('?', $url, 2);
+            parse_str($parameters, $query);
+        }
+
+        return [$url, $query];
+    }
+
+    /**
      * Fetches a view variable by name.
      *
      * If the view variable does not exist, null will be returned.

+ 13 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -73,6 +73,19 @@ class IntegrationTestCaseTest extends IntegrationTestCase
     }
 
     /**
+     * Test building a request, with query parameters
+     *
+     * @return void
+     */
+    public function testRequestBuildingQueryParameters()
+    {
+        $request = $this->_buildRequest('/tasks/view?archived=yes', 'GET', []);
+
+        $this->assertEquals('/tasks/view?archived=yes', $request->here());
+        $this->assertEquals('yes', $request->query('archived'));
+    }
+
+    /**
      * Test sending get requests.
      *
      * @return void