mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Improved robustness of FunctionalTest HTML testing.
Removed junk output from stderr git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60602 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1a73ef447e
commit
45ee7149d7
@ -17,7 +17,7 @@ class CSSContentParser extends Object {
|
||||
|
||||
function __construct($content) {
|
||||
$CLI_content = escapeshellarg($content);
|
||||
$tidy = `echo $CLI_content | tidy -n -q -utf8 -asxhtml`;
|
||||
$tidy = `echo $CLI_content | tidy -n -q -utf8 -asxhtml 2> /dev/null`;
|
||||
$tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"','',$tidy);
|
||||
$tidy = str_replace(' ','',$tidy);
|
||||
$this->simpleXML = new SimpleXMLElement($tidy);
|
||||
|
@ -142,12 +142,14 @@ class FunctionalTest extends SapphireTest {
|
||||
*/
|
||||
function assertPartialMatchBySelector($selector, $expectedMatches) {
|
||||
$items = $this->cssParser()->getBySelector($selector);
|
||||
foreach($items as $item) $actuals[trim(preg_replace("/[ \n\r\t]+/", " ", $item. ''))] = true;
|
||||
|
||||
$actuals = array();
|
||||
if($items) foreach($items as $item) $actuals[trim(preg_replace("/[ \n\r\t]+/", " ", $item. ''))] = true;
|
||||
|
||||
foreach($expectedMatches as $match) {
|
||||
if(!isset($actuals[$match])) {
|
||||
throw new PHPUnit_Framework_AssertionFailedError(
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "\n\n"
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n"
|
||||
. "Instead the following elements were found:\n'" . implode("'\n'", array_keys($actuals)) . "'"
|
||||
);
|
||||
return;
|
||||
@ -168,11 +170,13 @@ class FunctionalTest extends SapphireTest {
|
||||
*/
|
||||
function assertExactMatchBySelector($selector, $expectedMatches) {
|
||||
$items = $this->cssParser()->getBySelector($selector);
|
||||
foreach($items as $item) $actuals[] = trim(preg_replace("/[ \n\r\t]+/", " ", $item. ''));
|
||||
|
||||
$actuals = array();
|
||||
if($items) foreach($items as $item) $actuals[] = trim(preg_replace("/[ \n\r\t]+/", " ", $item. ''));
|
||||
|
||||
if($expectedMatches != $actuals) {
|
||||
throw new PHPUnit_Framework_AssertionFailedError(
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "\n\n"
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n"
|
||||
. "Instead the following elements were found:\n'" . implode("'\n'", $actuals) . "'"
|
||||
);
|
||||
}
|
||||
@ -190,12 +194,14 @@ class FunctionalTest extends SapphireTest {
|
||||
*/
|
||||
function assertPartialHTMLMatchBySelector($selector, $expectedMatches) {
|
||||
$items = $this->cssParser()->getBySelector($selector);
|
||||
foreach($items as $item) $actuals[$item->asXML()] = true;
|
||||
|
||||
$actuals = array();
|
||||
if($items) foreach($items as $item) $actuals[$item->asXML()] = true;
|
||||
|
||||
foreach($expectedMatches as $match) {
|
||||
if(!isset($actuals[$match])) {
|
||||
throw new PHPUnit_Framework_AssertionFailedError(
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "\n\n"
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n"
|
||||
. "Instead the following elements were found:\n'" . implode("'\n'", array_keys($actuals)) . "'"
|
||||
);
|
||||
return;
|
||||
@ -216,11 +222,13 @@ class FunctionalTest extends SapphireTest {
|
||||
*/
|
||||
function assertExactHTMLMatchBySelector($selector, $expectedMatches) {
|
||||
$items = $this->cssParser()->getBySelector($selector);
|
||||
foreach($items as $item) $actuals[] = $item->asXML();
|
||||
|
||||
$actuals = array();
|
||||
if($items) foreach($items as $item) $actuals[] = $item->asXML();
|
||||
|
||||
if($expectedMatches != $actuals) {
|
||||
throw new PHPUnit_Framework_AssertionFailedError(
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "\n\n"
|
||||
"Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n"
|
||||
. "Instead the following elements were found:\n'" . implode("'\n'", $actuals) . "'"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user