Skip to content
Permalink
Browse files

Add functions to test response body against regular expressions

  • Loading branch information...
Zuluru committed Dec 6, 2016
1 parent f8ea642 commit fa82b08b8cf5a832faf9f95cabb00550759f1459
Showing with 56 additions and 0 deletions.
  1. +30 −0 src/TestSuite/IntegrationTestCase.php
  2. +26 −0 tests/TestCase/TestSuite/IntegrationTestCaseTest.php
@@ -857,6 +857,36 @@ public function assertResponseNotContains($content, $message = '')
$this->assertNotContains($content, (string)$this->_response->body(), $message);
}
/**
* Asserts that the response body matches a given regular expression.
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertResponseRegExp($pattern, $message = '')
{
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertRegExp($pattern, (string)$this->_response->body(), $message);
}
/**
* Asserts that the response body does not match a given regular expression.
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertResponseNotRegExp($pattern, $message = '')
{
if (!$this->_response) {
$this->fail('No response set, cannot assert content. ' . $message);
}
$this->assertNotRegExp($pattern, (string)$this->_response->body(), $message);
}
/**
* Assert response content is not empty.
*
@@ -746,6 +746,32 @@ public function testAssertResponseNotContains()
$this->assertResponseNotContains('contents');
}
/**
* Test the content regexp assertion.
*
* @return void
*/
public function testAssertResponseRegExp()
{
$this->_response = new Response();
$this->_response->body('Some content');
$this->assertResponseRegExp('/cont/');
}
/**
* Test the negated content regexp assertion.
*
* @return void
*/
public function testAssertResponseNotRegExp()
{
$this->_response = new Response();
$this->_response->body('Some content');
$this->assertResponseNotRegExp('/cant/');
}
/**
* Test that works in tandem with testEventManagerReset2 to
* test the EventManager reset.

0 comments on commit fa82b08

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