Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add functions to test response body against regular expressions
  • Loading branch information
Zuluru committed Dec 6, 2016
1 parent f8ea642 commit fa82b08
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -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.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -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.
Expand Down

0 comments on commit fa82b08

Please sign in to comment.