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

Commit

Permalink
Merge branch 'hotfix/5212' into develop
Browse files Browse the repository at this point in the history
Forward port #5212
  • Loading branch information
weierophinney committed Oct 23, 2013
2 parents 29de088 + b0b46e2 commit d11ddd9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 45 deletions.
Expand Up @@ -49,7 +49,8 @@ public function assertHasResponseHeader($header)
$responseHeader = $this->getResponseHeader($header);
if (false === $responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" found', $header
'Failed asserting response header "%s" found',
$header
));
}
$this->assertNotEquals(false, $responseHeader);
Expand All @@ -65,7 +66,8 @@ public function assertNotHasResponseHeader($header)
$responseHeader = $this->getResponseHeader($header);
if (false !== $responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" WAS NOT found', $header
'Failed asserting response header "%s" WAS NOT found',
$header
));
}
$this->assertFalse($responseHeader);
Expand All @@ -82,13 +84,16 @@ public function assertResponseHeaderContains($header, $match)
$responseHeader = $this->getResponseHeader($header);
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header, header "%s" do not exists', $header
'Failed asserting response header, header "%s" do not exists',
$header
));
}
if ($match != $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" exists and contains "%s", actual content is "%s"',
$header, $match, $responseHeader->getFieldValue()
$header,
$match,
$responseHeader->getFieldValue()
));
}
$this->assertEquals($match, $responseHeader->getFieldValue());
Expand All @@ -105,13 +110,15 @@ public function assertNotResponseHeaderContains($header, $match)
$responseHeader = $this->getResponseHeader($header);
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header, header "%s" do not exists', $header
'Failed asserting response header, header "%s" do not exists',
$header
));
}
if ($match == $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" DOES NOT CONTAIN "%s"',
$header, $match
$header,
$match
));
}
$this->assertNotEquals($match, $responseHeader->getFieldValue());
Expand All @@ -128,13 +135,16 @@ public function assertResponseHeaderRegex($header, $pattern)
$responseHeader = $this->getResponseHeader($header);
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header, header "%s" do not exists', $header
'Failed asserting response header, header "%s" do not exists',
$header
));
}
if (!preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" exists and matches regex "%s", actual content is "%s"',
$header, $pattern, $responseHeader->getFieldValue()
$header,
$pattern,
$responseHeader->getFieldValue()
));
}
$this->assertTrue((bool) preg_match($pattern, $responseHeader->getFieldValue()));
Expand All @@ -151,13 +161,15 @@ public function assertNotResponseHeaderRegex($header, $pattern)
$responseHeader = $this->getResponseHeader($header);
if (!$responseHeader) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header, header "%s" do not exists', $header
'Failed asserting response header, header "%s" do not exists',
$header
));
}
if (preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response header "%s" DOES NOT MATCH regex "%s"',
$header, $pattern
$header,
$pattern
));
}
$this->assertFalse((bool) preg_match($pattern, $responseHeader->getFieldValue()));
Expand Down Expand Up @@ -208,7 +220,8 @@ public function assertRedirectTo($url)
if ($url != $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response redirects to "%s", actual redirection is "%s"',
$url, $responseHeader->getFieldValue()
$url,
$responseHeader->getFieldValue()
));
}
$this->assertEquals($url, $responseHeader->getFieldValue());
Expand All @@ -229,7 +242,8 @@ public function assertNotRedirectTo($url)
}
if ($url == $responseHeader->getFieldValue()) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response redirects to "%s"', $url
'Failed asserting response redirects to "%s"',
$url
));
}
$this->assertNotEquals($url, $responseHeader->getFieldValue());
Expand All @@ -251,7 +265,8 @@ public function assertRedirectRegex($pattern)
if (!preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response redirects to URL MATCHING "%s", actual redirection is "%s"',
$pattern, $responseHeader->getFieldValue()
$pattern,
$responseHeader->getFieldValue()
));
}
$this->assertTrue((bool) preg_match($pattern, $responseHeader->getFieldValue()));
Expand All @@ -272,7 +287,8 @@ public function assertNotRedirectRegex($pattern)
}
if (preg_match($pattern, $responseHeader->getFieldValue())) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting response DOES NOT redirect to URL MATCHING "%s"', $pattern
'Failed asserting response DOES NOT redirect to URL MATCHING "%s"',
$pattern
));
}
$this->assertFalse((bool) preg_match($pattern, $responseHeader->getFieldValue()));
Expand Down Expand Up @@ -351,7 +367,8 @@ private function queryAssertion($path, $useXpath = false)
$match = $this->$method($path);
if (!$match > 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
'Failed asserting node DENOTED BY %s EXISTS',
$path
));
}
$this->assertTrue($match > 0);
Expand Down Expand Up @@ -389,7 +406,8 @@ private function notQueryAssertion($path, $useXpath = false)
$match = $this->$method($path);
if ($match != 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT EXIST', $path
'Failed asserting node DENOTED BY %s DOES NOT EXIST',
$path
));
}
$this->assertEquals(0, $match);
Expand Down Expand Up @@ -429,7 +447,9 @@ private function queryCountAssertion($path, $count, $useXpath = false)
if ($match != $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS EXACTLY %d times, actually occurs %d times',
$path, $count, $match
$path,
$count,
$match
));
}
$this->assertEquals($match, $count);
Expand Down Expand Up @@ -471,7 +491,8 @@ private function notQueryCountAssertion($path, $count, $useXpath = false)
if ($match == $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT OCCUR EXACTLY %d times',
$path, $count
$path,
$count
));
}
$this->assertNotEquals($match, $count);
Expand Down Expand Up @@ -513,7 +534,9 @@ private function queryCountMinAssertion($path, $count, $useXpath = false)
if ($match < $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS AT LEAST %d times, actually occurs %d times',
$path, $count, $match
$path,
$count,
$match
));
}
$this->assertTrue($match >= $count);
Expand Down Expand Up @@ -555,7 +578,9 @@ private function queryCountMaxAssertion($path, $count, $useXpath = false)
if ($match > $count) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s OCCURS AT MOST %d times, actually occurs %d times',
$path, $count, $match
$path,
$count,
$match
));
}
$this->assertTrue($match <= $count);
Expand Down Expand Up @@ -595,16 +620,21 @@ private function queryContentContainsAssertion($path, $match, $useXpath = false)
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
'Failed asserting node DENOTED BY %s EXISTS',
$path
));
}
if ($result->current()->nodeValue != $match) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node denoted by %s CONTAINS content "%s", actual content is "%s"',
$path, $match, $result->current()->nodeValue
));
foreach ($result as $node) {
if ($node->nodeValue == $match) {
$this->assertEquals($match, $node->nodeValue);
return;
}
}
$this->assertEquals($result->current()->nodeValue, $match);
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node denoted by %s CONTAINS content "%s"',
$path,
$match
));
}

/**
Expand Down Expand Up @@ -641,16 +671,21 @@ private function notQueryContentContainsAssertion($path, $match, $useXpath = fal
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
'Failed asserting node DENOTED BY %s EXISTS',
$path
));
}
if ($result->current()->nodeValue == $match) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT CONTAIN content "%s"',
$path, $match
));
foreach ($result as $node) {
if ($node->nodeValue == $match) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT CONTAIN content "%s"',
$path,
$match
));
}
}
$this->assertNotEquals($result->current()->nodeValue, $match);
$currentValue = $node->nodeValue;
$this->assertNotEquals($currentValue, $match);
}

/**
Expand Down Expand Up @@ -687,13 +722,16 @@ private function queryContentRegexAssertion($path, $pattern, $useXpath = false)
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
'Failed asserting node DENOTED BY %s EXISTS',
$path
));
}
if (!preg_match($pattern, $result->current()->nodeValue)) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node denoted by %s CONTAINS content MATCHING "%s", actual content is "%s"',
$path, $pattern, $result->current()->nodeValue
$path,
$pattern,
$result->current()->nodeValue
));
}
$this->assertTrue((bool) preg_match($pattern, $result->current()->nodeValue));
Expand Down Expand Up @@ -733,13 +771,15 @@ private function notQueryContentRegexAssertion($path, $pattern, $useXpath = fals
$result = $this->query($path, $useXpath);
if ($result->count() == 0) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s EXISTS', $path
'Failed asserting node DENOTED BY %s EXISTS',
$path
));
}
if (preg_match($pattern, $result->current()->nodeValue)) {
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
'Failed asserting node DENOTED BY %s DOES NOT CONTAIN content MATCHING "%s"',
$path, $pattern
$path,
$pattern
));
}
$this->assertFalse((bool) preg_match($pattern, $result->current()->nodeValue));
Expand Down
Expand Up @@ -333,22 +333,31 @@ public function testAssertQueryContentContains()
$this->assertQueryContentContains('div#content', 'foo');

$this->setExpectedException(
'PHPUnit_Framework_ExpectationFailedException',
'actual content is "foo"' // check actual content is display
'PHPUnit_Framework_ExpectationFailedException'
);
$this->assertQueryContentContains('div#content', 'bar');
}

public function testAssertQueryContentContainsWithSecondElement()
{
$this->dispatch('/tests');
$this->assertQueryContentContains('div#content', 'foo');

$this->setExpectedException(
'PHPUnit_Framework_ExpectationFailedException'
);
$this->assertQueryContentContains('div.top', 'bar');
}

public function testAssertXpathQueryContentContains()
{
$this->dispatch('/tests');
$this->assertXpathQueryContentContains('//div[@id="content"]', 'foo');
$this->assertXpathQueryContentContains('//div[@class="top"]', 'foo');

$this->setExpectedException(
'PHPUnit_Framework_ExpectationFailedException',
'actual content is "foo"' // check actual content is display
'PHPUnit_Framework_ExpectationFailedException'
);
$this->assertXpathQueryContentContains('//div[@id="content"]', 'bar');
$this->assertXpathQueryContentContains('//div[@class="top"]', 'bar');
}

public function testAssertNotQueryContentContains()
Expand Down
Expand Up @@ -3,7 +3,7 @@
<div id="content">foo</div>

<div class="top"></div>
<div class="top"></div>
<div class="top">foo</div>
<div class="top"></div>

<?php for ($i = 0; $i < $num_get; $i++): ?>
Expand Down

0 comments on commit d11ddd9

Please sign in to comment.