Skip to content
Permalink
Browse files

Add assertRedirect()

  • Loading branch information...
markstory committed Sep 2, 2014
1 parent 7038e6a commit ac5f98f3066d2977bebc8c0f50eb473b7725cc39
Showing with 32 additions and 0 deletions.
  1. +19 −0 src/TestSuite/IntegrationTestCase.php
  2. +13 −0 tests/TestCase/TestSuite/IntegrationTestCaseTest.php
@@ -18,6 +18,7 @@
use Cake\Network\Request;
use Cake\Network\Session;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\TestSuite\Stub\Response;
@@ -281,4 +282,22 @@ protected function _assertStatus($min, $max, $message) {
$this->assertLessThanOrEqual($max, $status, $message);
}
/**
* Assert that the Location header is correct.
*
* @param string|array $url The url you expected the client to go to. This
* cane either be a string URL or an array compatible with Router::url()
* @return void
*/
public function assertRedirect($url, $message = '') {
if (!$this->_response) {
$this->fail('Not response set, cannot assert location header. ' . $message);
}
$result = $this->_response->header();
if (empty($result['Location'])) {
$this->fail('No location header set. ' . $message);
}
$this->assertEquals(Router::url($url, ['_full' => true]), $result['Location']);
}
}
@@ -105,4 +105,17 @@ public function testAssertResponseStatusCodes() {
$this->assertResponseFailure();
}
/**
* Test the location header assertion.
*
* @return void
*/
public function testAssertRedirect() {
$this->_response = new Response();
$this->_response->header('Location', 'http://localhost/tasks/index');
$this->assertRedirect('/tasks/index');
$this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);
}
}

0 comments on commit ac5f98f

Please sign in to comment.
You can’t perform that action at this time.