0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-18 18:25:18 +00:00

[3.1.0] When flush fails, fail SimpleTest

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1641 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-04-03 21:24:16 +00:00
parent 1d25be875d
commit e78df4dc9f
5 changed files with 53 additions and 27 deletions

2
NEWS
View File

@ -80,6 +80,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
. HTMLPURIFIER_STRICT removed; no validation is performed on runtime, only
during cache generation
. Reordered script calls in maintenance/flush.php
. Command line scripts now honor exit codes
. When --flush fails in unit testers, abort tests and print message
3.0.0, released 2008-01-06
# HTML Purifier is PHP 5 only! The 2.1.x branch will be maintained

3
TODO
View File

@ -27,9 +27,6 @@ DOCUMENTATION
IMPORTANT FEATURES
- Get everything into configuration objects (filters, I'm looking at you)
- Factor out command line parser into its own class, and unit test it
- Verbose mode for webtester that includes transcript from command line
- Command line maintenance scripts must complain with exit(1) if there are
fatal errors
- Emit notices when aliases are used (allow muting these errors)
CONFIGDOC

View File

@ -178,3 +178,33 @@ function printTokens($tokens, $index = null) {
$string .= '</pre>';
echo $string;
}
/**
* Convenient "insta-fail" test-case to add if any outside things fail
*/
class FailedTest extends UnitTestCase {
protected $msg, $details;
public function __construct($msg, $details = null) {
$this->msg = $msg;
$this->details = $details;
}
public function test() {
$this->fail($this->msg);
if ($this->details) $this->_reporter->paintFormattedMessage($this->details);
}
}
/**
* Flushes all caches, and fatally errors out if there's a problem.
*/
function htmlpurifier_flush($php, $reporter) {
exec($php . ' ../maintenance/flush.php', $out, $status);
if ($status) {
$test = new FailedTest(
'maintenance/flush.php returned non-zero exit status',
wordwrap(implode("\n", $out), 80)
);
$test->run($reporter);
exit(1);
}
}

View File

@ -59,12 +59,17 @@ if ($AC['disable-phpt'] && $AC['only-phpt']) {
// Shell-script code is executed
if ($AC['xml']) {
if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
$reporter = new XmlReporter();
} elseif (SimpleReporter::inCli()) {
$reporter = new TextReporter();
} else {
$reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
}
if ($AC['flush']) {
if (SimpleReporter::inCli() && !$AC['xml']) {
passthru($AC['php'] . ' ../maintenance/flush.php');
} else {
shell_exec($AC['php'] . ' ../maintenance/flush.php');
}
htmlpurifier_flush($AC['php'], $reporter);
}
// initialize and load HTML Purifier
@ -157,15 +162,6 @@ if ($AC['file']) {
}
if ($AC['xml']) {
if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
$reporter = new XmlReporter();
} elseif (SimpleReporter::inCli()) {
$reporter = new TextReporter();
} else {
$reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
}
if ($AC['dry']) $reporter->makeDry();
$test->run($reporter);

View File

@ -46,10 +46,15 @@ $aliases = array(
);
htmlpurifier_parse_args($AC, $aliases);
// Regenerate any necessary files
shell_exec($AC['php'] . ' ../maintenance/flush.php');
if ($AC['xml']) {
$reporter = new XmlReporter();
} else {
$reporter = new TextReporter();
}
// Regenerate any necessary files
htmlpurifier_flush($AC['php'], $reporter);
$test = new TestSuite('HTML Purifier Multiple Versions Test');
$file = '';
$test_files = array();
@ -59,13 +64,14 @@ if ($AC['file']) {
if (isset($test_files_lookup[$AC['file']])) {
$file = '--file=' . $AC['file'];
} else {
echo "Invalid file passed\n";
exit;
throw new Exception("Invalid file passed");
}
}
// This allows us to get out of having to do dry runs.
$size = count($test_files);
// Setup the test
$test = new TestSuite('HTML Purifier Multiple Versions Test');
foreach ($versions_to_test as $version) {
$flush = '';
if (is_array($version)) {
@ -104,11 +110,6 @@ foreach ($versions_to_test as $version) {
// add more websites, i.e. more configurations to test.
$test->addTestCase(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1'));
if ($AC['xml']) {
$reporter = new XmlReporter();
} else {
$reporter = new TextReporter();
}
$test->run($reporter);
shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');