Skip to content

Commit

Permalink
Merge pull request #8037 from jeremyharris/asserthtml-fulldebug-fix
Browse files Browse the repository at this point in the history
Fixed fullDebug for TestCase::assertHtml
  • Loading branch information
markstory committed Jan 15, 2016
2 parents cc17111 + 39ac722 commit a449b22
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/TestSuite/TestCase.php
Expand Up @@ -437,7 +437,11 @@ public function assertHtml($expected, $string, $fullDebug = false)
foreach ($regex as $i => $assertion) {
$matches = false;
if (isset($assertion['attrs'])) {
$string = $this->_assertAttributes($assertion, $string);
$string = $this->_assertAttributes($assertion, $string, $fullDebug, $regex);
if ($fullDebug === true && $string === false) {
debug($string, true);
debug($regex, true);
}
continue;
}

Expand All @@ -451,11 +455,11 @@ public function assertHtml($expected, $string, $fullDebug = false)
}
}
if (!$matches) {
$this->assertRegExp($expression, $string, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
if ($fullDebug) {
debug($string, true);
debug($regex, true);
if ($fullDebug === true) {
debug($string);
debug($regex);
}
$this->assertRegExp($expression, $string, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
return false;
}
}
Expand All @@ -469,9 +473,11 @@ public function assertHtml($expected, $string, $fullDebug = false)
*
* @param array $assertions Assertions to run.
* @param string $string The HTML string to check.
* @param bool $fullDebug Whether or not more verbose output should be used.
* @param array $regex Full regexp from `assertHtml`
* @return string
*/
protected function _assertAttributes($assertions, $string)
protected function _assertAttributes($assertions, $string, $fullDebug = false, $regex = '')
{
$asserts = $assertions['attrs'];
$explains = $assertions['explains'];
Expand All @@ -488,6 +494,10 @@ protected function _assertAttributes($assertions, $string)
}
}
if ($matches === false) {
if ($fullDebug === true) {
debug($string);
debug($regex);
}
$this->assertTrue(false, 'Attribute did not match. Was expecting ' . $explains[$j]);
}
$len = count($asserts);
Expand Down

0 comments on commit a449b22

Please sign in to comment.