Skip to content

Commit

Permalink
Implement assertRedirectContains()
Browse files Browse the repository at this point in the history
Being able to assert substrings of redirect URLs can be helpful when
generating URLs to external services.

Refs #6114
  • Loading branch information
markstory committed Mar 20, 2015
1 parent a3ee837 commit 55e8d69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -473,6 +473,25 @@ public function assertRedirect($url = null, $message = '')
$this->assertEquals(Router::url($url, ['_full' => true]), $result['Location'], $message);
}

/**
* Asserts that the Location header contains a substring
*
* @param string $url The URL you expected the client to go to.
* @param string $message The failure message that will be appended to the generated message.
* @return void
*/
public function assertRedirectContains($url = null, $message = '')
{
if (!$this->_response) {
$this->fail('No response set, cannot assert location header. ' . $message);
}
$result = $this->_response->header();
if (empty($result['Location'])) {
$this->fail('No location header set. ' . $message);
}
$this->assertContains($url, $result['Location'], $message);
}

/**
* Asserts that the Location header is not set.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -242,6 +242,19 @@ public function testAssertNoRedirectFail()
$this->assertEquals(1, $result->failureCount());
}

/**
* Test the location header assertion string contains
*
* @return void
*/
public function testAssertRedirectContains()
{
$this->_response = new Response();
$this->_response->header('Location', 'http://localhost/tasks/index');

$this->assertRedirectContains('/tasks/index');
}

/**
* Test the header assertion.
*
Expand Down

0 comments on commit 55e8d69

Please sign in to comment.