Skip to content

Commit

Permalink
Add more assertion methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 3, 2014
1 parent cbe427b commit 00ed67e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -312,6 +312,44 @@ public function assertRedirect($url, $message = '') {
$this->assertEquals(Router::url($url, ['_full' => true]), $result['Location'], $message);
}

/**
* Assert response headers
*
* @param string $header The header to check
* @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 assertHeader($header, $content, $message = '') {
if (!$this->_response) {
$this->fail('No response set, cannot assert headers. ' . $message);
}
$headers = $this->_response->header();
if (!isset($headers[$header])) {
$this->fail("The '$header' header is not set. " . $message);
}
$this->assertEquals($headers[$header], $content, $message);
}

/**
* Assert content type
*
* @param string $type The content-type to check for.
* @param string $message The failure message that will be appended to the generated message.
* @return void
*/
public function assertContentType($type, $message = '') {
if (!$this->_response) {
$this->fail('No response set, cannot assert content-type. ' . $message);
}
$alias = $this->_response->getMimeType($type);
if ($alias !== false) {
$type = $alias;
}
$result = $this->_response->type();
$this->assertEquals($type, $result, $message);
}

/**
* Assert content exists in the response body.
*
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -118,6 +118,31 @@ public function testAssertRedirect() {
$this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);
}

/**
* Test the header assertino
*
* @return void
*/
public function testAssertHeader() {
$this->_response = new Response();
$this->_response->header('Etag', 'abc123');

$this->assertHeader('Etag', 'abc123');
}

/**
* Test the content type assertino
*
* @return void
*/
public function testAssertContentType() {
$this->_response = new Response();
$this->_response->type('json');

$this->assertContentType('json');
$this->assertContentType('application/json');
}

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

0 comments on commit 00ed67e

Please sign in to comment.