diff --git a/src/TestSuite/IntegrationTestCase.php b/src/TestSuite/IntegrationTestCase.php index 1ddeb16a326..4cf3973d3fc 100644 --- a/src/TestSuite/IntegrationTestCase.php +++ b/src/TestSuite/IntegrationTestCase.php @@ -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. * diff --git a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php index e6ca89fcd76..58dd54da8df 100644 --- a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php +++ b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php @@ -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. *