Skip to content
Permalink
Browse files

Add assertResponseContains() to IntegrationTestCase.

  • Loading branch information...
markstory committed Sep 3, 2014
1 parent 4b7ccf1 commit cbe427bdfbdaa334b55219b8506f57ff44e05a63
Showing with 29 additions and 2 deletions.
  1. +16 −1 src/TestSuite/IntegrationTestCase.php
  2. +13 −1 tests/TestCase/TestSuite/IntegrationTestCaseTest.php
@@ -298,6 +298,7 @@ protected function _assertStatus($min, $max, $message) {
*
* @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 $message The failure message that will be appended to the generated message.
* @return void
*/
public function assertRedirect($url, $message = '') {
@@ -308,7 +309,21 @@ public function assertRedirect($url, $message = '') {
if (empty($result['Location'])) {
$this->fail('No location header set. ' . $message);
}
$this->assertEquals(Router::url($url, ['_full' => true]), $result['Location']);
$this->assertEquals(Router::url($url, ['_full' => true]), $result['Location'], $message);
}
/**
* Assert content exists in the response body.
*
* @param string $content The content to check for.
* @param string $message The failure message that will be appended to the generated message.
* @return void
*/
public function assertResponseContains($content, $message = '') {
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertContains($content, $this->_response->body(), $message);
}
}
@@ -9,7 +9,7 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @since 2.0.0
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\TestSuite;
@@ -118,4 +118,16 @@ public function testAssertRedirect() {
$this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);
}
/**
* Test the content assertion.
*
* @return void
*/
public function testAssertResponseContains() {
$this->_response = new Response();
$this->_response->body('Some content');
$this->assertResponseContains('content');
}
}

0 comments on commit cbe427b

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