mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-16 11:03:58 +02:00
[3.0.0] Upgraded test scripts and other goodies. Also removed some PHP4 cruft.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1482 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -1,19 +1,38 @@
|
||||
<?php
|
||||
|
||||
// call one file using /?f=FileTest.php , see $test_files array for
|
||||
// valid values
|
||||
/** @file
|
||||
* Unit tester
|
||||
*
|
||||
* The heart and soul of HTML Purifier's correctness; anything and everything
|
||||
* is tested here! Arguments are specified like --arg=opt, allowed arguments
|
||||
* are:
|
||||
* - flush, whether or not to flush definition caches before running
|
||||
* - standalone, whether or not to test the standalone version
|
||||
* - file (f), a single file to test
|
||||
* - xml, whether or not to output XML
|
||||
*/
|
||||
|
||||
define('HTMLPurifierTest', 1);
|
||||
define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
$AC = array(); // parameters
|
||||
$AC['flush'] = false;
|
||||
$AC['standalone'] = false;
|
||||
$AC['file'] = '';
|
||||
$AC['xml'] = false;
|
||||
$aliases = array(
|
||||
'f' => 'file',
|
||||
);
|
||||
htmlpurifier_parse_args($AC, $aliases);
|
||||
|
||||
// clean out cache if necessary
|
||||
if (isset($_GET['flush'])) shell_exec('php ../maintenance/flush-definition-cache.php');
|
||||
if ($AC['flush']) shell_exec('php ../maintenance/flush-definition-cache.php');
|
||||
|
||||
// initialize and load HTML Purifier
|
||||
// use ?standalone to load the alterative standalone stub
|
||||
if (isset($_GET['standalone']) || (isset($argv[1]) && $argv[1] == 'standalone')) {
|
||||
if ($AC['standalone']) {
|
||||
set_include_path(realpath('blanks') . PATH_SEPARATOR . get_include_path());
|
||||
require_once '../library/HTMLPurifier.standalone.php';
|
||||
} else {
|
||||
@@ -33,25 +52,25 @@ $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
|
||||
$test_file_lookup = array_flip($test_files);
|
||||
|
||||
// determine test file
|
||||
if (isset($_GET['f']) && isset($test_file_lookup[$_GET['f']])) {
|
||||
$GLOBALS['HTMLPurifierTest']['File'] = $_GET['f'];
|
||||
} elseif (isset($argv[1]) && isset($test_file_lookup[$argv[1]])) {
|
||||
// command-line
|
||||
$GLOBALS['HTMLPurifierTest']['File'] = $argv[1];
|
||||
} else {
|
||||
$GLOBALS['HTMLPurifierTest']['File'] = false;
|
||||
if ($AC['file']) {
|
||||
if (!isset($test_file_lookup[$AC['file']])) {
|
||||
echo "Invalid file passed\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
|
||||
if ($test_file = $GLOBALS['HTMLPurifierTest']['File']) {
|
||||
if ($AC['file']) {
|
||||
|
||||
$test = new GroupTest($test_file);
|
||||
require_once $test_file;
|
||||
$test->addTestClass(path2class($test_file));
|
||||
$test = new TestSuite($AC['file']);
|
||||
require_once $AC['file'];
|
||||
$test->addTestClass(path2class($AC['file']));
|
||||
|
||||
} else {
|
||||
|
||||
$test = new GroupTest('All HTML Purifier tests on PHP ' . PHP_VERSION);
|
||||
$standalone = '';
|
||||
if ($AC['standalone']) $standalone = ' (standalone)';
|
||||
$test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
|
||||
foreach ($test_files as $test_file) {
|
||||
require_once $test_file;
|
||||
$test->addTestClass(path2class($test_file));
|
||||
@@ -59,7 +78,13 @@ if ($test_file = $GLOBALS['HTMLPurifierTest']['File']) {
|
||||
|
||||
}
|
||||
|
||||
if (SimpleReporter::inCli()) $reporter = new TextReporter();
|
||||
else $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8');
|
||||
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);
|
||||
}
|
||||
|
||||
$test->run($reporter);
|
||||
|
Reference in New Issue
Block a user