Browse Source

Allow simple check on existent for assertRedirect()

Mark Scherer 11 years ago
parent
commit
2b28ea0694

+ 7 - 3
src/TestSuite/IntegrationTestCase.php

@@ -441,17 +441,21 @@ abstract class IntegrationTestCase extends TestCase
     /**
      * Asserts that the Location header is correct.
      *
-     * @param string|array $url The url you expected the client to go to. This
-     *   can either be a string URL or an array compatible with Router::url()
+     * @param string|array|null $url The URL you expected the client to go to. This
+     *   can either be a string URL or an array compatible with Router::url(). Use null to
+     *   simply check for the existence of this header.
      * @param string $message The failure message that will be appended to the generated message.
      * @return void
      */
-    public function assertRedirect($url, $message = '')
+    public function assertRedirect($url = null, $message = '')
     {
         if (!$this->_response) {
             $this->fail('No response set, cannot assert location header. ' . $message);
         }
         $result = $this->_response->header();
+        if ($url === null) {
+            return $this->assertNotEmpty($result['Location']);
+        }
         if (empty($result['Location'])) {
             $this->fail('No location header set. ' . $message);
         }

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

@@ -178,6 +178,7 @@ class IntegrationTestCaseTest extends IntegrationTestCase
         $this->_response = new Response();
         $this->_response->header('Location', 'http://localhost/tasks/index');
 
+        $this->assertRedirect();
         $this->assertRedirect('/tasks/index');
         $this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);
     }