From 25551c4b781f9f99f8430c2ed8348ee0b02d6195 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 21 Jan 2008 20:27:26 +0000 Subject: [PATCH] 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 --- NEWS | 1 + tests/CliTestCase.php | 22 +++++++++++++++++----- tests/common.php | 1 + tests/index.php | 1 + tests/multitest.php | 20 ++++++++++++++------ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index ca195210..52b1ff02 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/tests/CliTestCase.php b/tests/CliTestCase.php index c58d4873..8d9d362b 100644 --- a/tests/CliTestCase.php +++ b/tests/CliTestCase.php @@ -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->_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() diff --git a/tests/common.php b/tests/common.php index 494b6caf..12007b34 100644 --- a/tests/common.php +++ b/tests/common.php @@ -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) { diff --git a/tests/index.php b/tests/index.php index 5433f381..66dbbc2a 100755 --- a/tests/index.php +++ b/tests/index.php @@ -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); diff --git a/tests/multitest.php b/tests/multitest.php index 69116bad..39cd050a 100644 --- a/tests/multitest.php +++ b/tests/multitest.php @@ -34,8 +34,8 @@ if (!SimpleReporter::inCli()) { $AC = array(); // parameters $AC['exclude-normal'] = false; $AC['exclude-standalone'] = false; -$AC['file'] = ''; -$AC['xml'] = false; +$AC['file'] = ''; +$AC['xml'] = false; $AC['quiet'] = false; $aliases = array( 'f' => '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 {