Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Forward port #3841
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Mar 5, 2013
2 parents a9c87ac + 7e7f788 commit 47297fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Expand Up @@ -170,9 +170,9 @@ public function assertRedirect()
{
$responseHeader = $this->getResponseHeader('Location');
if (false === $responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
throw new PHPUnit_Framework_ExpectationFailedException(
'Failed asserting response is NOT a redirect'
));
);
}
$this->assertNotEquals(false, $responseHeader);
}
Expand Down Expand Up @@ -203,9 +203,9 @@ public function assertRedirectTo($url)
{
$responseHeader = $this->getResponseHeader('Location');
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
throw new PHPUnit_Framework_ExpectationFailedException(
'Failed asserting response is a redirect'
));
);
}
if ($url != $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
Expand All @@ -226,9 +226,9 @@ public function assertNotRedirectTo($url)
{
$responseHeader = $this->getResponseHeader('Location');
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
throw new PHPUnit_Framework_ExpectationFailedException(
'Failed asserting response is a redirect'
));
);
}
if ($url == $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
Expand All @@ -247,9 +247,9 @@ public function assertRedirectRegex($pattern)
{
$responseHeader = $this->getResponseHeader('Location');
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
throw new PHPUnit_Framework_ExpectationFailedException(
'Failed asserting response is a redirect'
));
);
}
if (!preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
Expand All @@ -269,9 +269,9 @@ public function assertNotRedirectRegex($pattern)
{
$responseHeader = $this->getResponseHeader('Location');
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
throw new PHPUnit_Framework_ExpectationFailedException(
'Failed asserting response is a redirect'
));
);
}
if (preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
Expand Down Expand Up @@ -427,7 +427,8 @@ public function assertNotXpathQuery($path)
*/
private function queryCountAssertion($path, $count, $useXpath = false)
{
$match = $this->queryCount($path);
$method = $useXpath ? 'xpathQueryCount' : 'queryCount';
$match = $this->$method($path);
if ($match != $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS EXACTLY %d times, actually occurs %d times',
Expand Down Expand Up @@ -468,7 +469,8 @@ public function assertXpathQueryCount($path, $count)
*/
private function notQueryCountAssertion($path, $count, $useXpath = false)
{
$match = $this->queryCount($path);
$method = $useXpath ? 'xpathQueryCount' : 'queryCount';
$match = $this->$method($path);
if ($match == $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT OCCUR EXACTLY %d times',
Expand Down Expand Up @@ -509,7 +511,8 @@ public function assertNotXpathQueryCount($path, $count)
*/
private function queryCountMinAssertion($path, $count, $useXpath = false)
{
$match = $this->queryCount($path);
$method = $useXpath ? 'xpathQueryCount' : 'queryCount';
$match = $this->$method($path);
if ($match < $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS AT LEAST %d times, actually occurs %d times',
Expand Down Expand Up @@ -550,7 +553,8 @@ public function assertXpathQueryCountMin($path, $count)
*/
private function queryCountMaxAssertion($path, $count, $useXpath = false)
{
$match = $this->queryCount($path);
$method = $useXpath ? 'xpathQueryCount' : 'queryCount';
$match = $this->$method($path);
if ($match > $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS AT MOST %d times, actually occurs %d times',
Expand Down Expand Up @@ -591,7 +595,7 @@ public function assertXpathQueryCountMax($path, $count)
*/
private function queryContentContainsAssertion($path, $match, $useXpath = false)
{
$result = $this->query($path);
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
Expand Down Expand Up @@ -637,7 +641,7 @@ public function assertXpathQueryContentContains($path, $match)
*/
private function notQueryContentContainsAssertion($path, $match, $useXpath = false)
{
$result = $this->query($path);
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
Expand Down Expand Up @@ -683,7 +687,7 @@ public function assertNotXpathQueryContentContains($path, $match)
*/
private function queryContentRegexAssertion($path, $pattern, $useXpath = false)
{
$result = $this->query($path);
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
Expand Down Expand Up @@ -729,7 +733,7 @@ public function assertXpathQueryContentRegex($path, $pattern)
*/
private function notQueryContentRegexAssertion($path, $pattern, $useXpath = false)
{
$result = $this->query($path);
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
Expand Down
Expand Up @@ -199,6 +199,14 @@ public function testAssertXpathQuery()
$this->assertXpathQuery('//form[@id="id"]');
}

public function testAssertXpathQueryWithBadXpathUsage()
{
$this->dispatch('/tests');

$this->setExpectedException('ErrorException');
$this->assertXpathQuery('form#myform');
}

public function testAssertNotQuery()
{
$this->dispatch('/tests');
Expand Down Expand Up @@ -241,6 +249,12 @@ public function testAssertXpathQueryCount()
$this->assertXpathQueryCount('//div[@class="top"]', 2);
}

public function testAssertXpathQueryCountWithBadXpathUsage()
{
$this->dispatch('/tests');
$this->assertXpathQueryCount('div.top', 0);
}

public function testAssertNotQueryCount()
{
$this->dispatch('/tests');
Expand Down

0 comments on commit 47297fd

Please sign in to comment.