0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +00:00

Support dry runs in SimpleTest, as well as misc other improvements.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1514 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-01-21 20:27:26 +00:00
parent c9bf2e8489
commit 25551c4b78
5 changed files with 34 additions and 11 deletions

1
NEWS
View File

@ -16,6 +16,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
. Plugins now get their own changelogs according to project conventions.
. Convert tokens to use instanceof, reducing memory footprint and
improving comparison speed.
. Dry runs now supported in SimpleTest; testing facilities improved
3.0.0, released 2008-01-06
# HTML Purifier is PHP 5 only! The 2.1.x branch will be maintained

View File

@ -10,23 +10,28 @@ class CliTestCase
public $_out = false;
public $_quiet = false;
public $_errors = array();
public $_size = false;
/**
* @param $command Command to execute to retrieve XML
* @param $xml Whether or not to suppress error messages
*/
public function __construct($command, $quiet = false) {
public function __construct($command, $quiet = false, $size = false) {
$this->_command = $command;
$this->_quiet = $quiet;
$this->_size = $size;
}
public function getLabel() {
return $this->_command;
}
public function run(&$reporter) {
if (!$this->_quiet) $reporter->paintFormattedMessage('Running ['.$this->_command.']');
$xml = shell_exec($this->_command);
return $this->_invokeCommand($this->_command, $reporter);
}
public function _invokeCommand($command, &$reporter) {
$xml = shell_exec($command);
if (! $xml) {
if (!$this->_quiet) {
trigger_error('Command did not have any output [' . $this->_command . ']');
trigger_error('Command did not have any output [' . $command . ']');
}
return false;
}
@ -59,7 +64,14 @@ class CliTestCase
return $parser;
}
public function getSize() {
return 1; // we don't know it
// This code properly does the dry run and allows for proper test
// case reporting but it's REALLY slow, so I don't recommend it.
if ($this->_size === false) {
$reporter = new SimpleReporter();
$this->_invokeCommand($this->_command . ' --dry', $reporter);
$this->_size = $reporter->getTestCaseCount();
}
return $this->_size;
}
public function _errorHandler($a, $b, $c, $d) {
$this->_errors[] = array($a, $b, $c, $d); // see set_error_handler()

View File

@ -25,6 +25,7 @@ require_once $simpletest_location . 'unit_tester.php';
require_once $simpletest_location . 'reporter.php';
require_once $simpletest_location . 'mock_objects.php';
require_once $simpletest_location . 'xml.php';
require_once $simpletest_location . 'remote.php';
// load CSS Tidy
if ($csstidy_location !== false) {

View File

@ -10,6 +10,7 @@
* - standalone, whether or not to test the standalone version
* - file (f), a single file to test
* - xml, whether or not to output XML
* - dry, whether or not to do a dry run
*/
define('HTMLPurifierTest', 1);

View File

@ -48,9 +48,10 @@ shell_exec('php ../maintenance/flush-definition-cache.php');
$test = new TestSuite('HTML Purifier Multiple Versions Test');
$file = '';
$test_files = array();
require 'test_files.php';
if ($AC['file']) {
$test_files = array();
require 'test_files.php';
$test_files_lookup = array_flip($test_files);
if (isset($test_files_lookup[$AC['file']])) {
$file = '--file=' . $AC['file'];
@ -59,16 +60,23 @@ if ($AC['file']) {
exit;
}
}
// This allows us to get out of having to do dry runs.
$size = count($test_files);
foreach ($versions_to_test as $version) {
$flush = '';
if (is_array($version)) {
$version = $version[0];
$flush = '--flush';
}
if (!$AC['exclude-normal']) $test->addTestCase(new CliTestCase("$phpv $version index.php --xml $flush $file", $AC['quiet']));
if (!$AC['exclude-standalone']) $test->addTestCase(new CliTestCase("$phpv $version index.php --xml --standalone $file", $AC['quiet']));
if (!$AC['exclude-normal']) $test->addTestCase(new CliTestCase("$phpv $version index.php --xml $flush $file", $AC['quiet'], $size));
if (!$AC['exclude-standalone']) $test->addTestCase(new CliTestCase("$phpv $version index.php --xml --standalone $file", $AC['quiet'], $size));
}
// This is the HTML Purifier website's test XML file. We could
// add more websites, i.e. more configurations to test.
$test->addTestCase(new RemoteTestCase('http://localhost/htmlpurifier/tests/?xml', 'http://localhost/htmlpurifier/tests/?xml&dry'));
if ($AC['xml']) {
$reporter = new XmlReporter();
} else {