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

Commit

Permalink
Merge pull request zendframework/zendframework#5212 from EpeeCheeze/m…
Browse files Browse the repository at this point in the history
…aster

assertQueryContentContains searching through all nodes found
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
30 changes: 18 additions & 12 deletions src/PHPUnit/Controller/AbstractHttpControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,16 @@ private function queryContentContainsAssertion($path, $match, $useXpath = false)
'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 @@ -644,13 +647,16 @@ private function notQueryContentContainsAssertion($path, $match, $useXpath = fal
'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
));
}
$currentValue = $node->nodeValue;
}
$this->assertNotEquals($result->current()->nodeValue, $match);
$this->assertNotEquals($currentValue, $match);
}

/**
Expand Down
21 changes: 15 additions & 6 deletions test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion test/_files/Baz/view/baz/index/unittests.phtml
Original file line number Diff line number Diff line change
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 752ddd9

Please sign in to comment.