Skip to content
Permalink
Browse files

Add more assertion methods.

  • Loading branch information...
markstory committed Sep 3, 2014
1 parent cbe427b commit 00ed67e88ca87ef43beb1d6f9ee6117ec8d33c11
Showing with 63 additions and 0 deletions.
  1. +38 −0 src/TestSuite/IntegrationTestCase.php
  2. +25 −0 tests/TestCase/TestSuite/IntegrationTestCaseTest.php
@@ -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.
*
@@ -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.
*

0 comments on commit 00ed67e

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