2006-07-23 00:11:03 +00:00
|
|
|
<?php
|
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
/** @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
|
2008-01-21 20:27:26 +00:00
|
|
|
* - dry, whether or not to do a dry run
|
2008-01-07 00:17:49 +00:00
|
|
|
*/
|
2007-01-19 03:54:55 +00:00
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
define('HTMLPurifierTest', 1);
|
2007-09-03 15:16:33 +00:00
|
|
|
define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
|
2008-02-10 21:34:52 +00:00
|
|
|
chdir(dirname(__FILE__));
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2008-01-06 19:31:21 +00:00
|
|
|
require_once 'common.php';
|
2007-12-12 21:46:30 +00:00
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
$AC = array(); // parameters
|
|
|
|
$AC['flush'] = false;
|
|
|
|
$AC['standalone'] = false;
|
|
|
|
$AC['file'] = '';
|
|
|
|
$AC['xml'] = false;
|
2008-01-21 19:27:55 +00:00
|
|
|
$AC['dry'] = false;
|
2008-01-07 00:17:49 +00:00
|
|
|
$aliases = array(
|
|
|
|
'f' => 'file',
|
|
|
|
);
|
|
|
|
htmlpurifier_parse_args($AC, $aliases);
|
|
|
|
|
2008-01-06 19:31:21 +00:00
|
|
|
// clean out cache if necessary
|
2008-01-07 00:17:49 +00:00
|
|
|
if ($AC['flush']) shell_exec('php ../maintenance/flush-definition-cache.php');
|
2006-08-10 12:41:39 +00:00
|
|
|
|
2008-01-27 05:31:06 +00:00
|
|
|
// setup our own autoload for earlier PHP versions
|
|
|
|
if (!function_exists('spl_autoload_register')) {
|
|
|
|
function __autoload($class) {
|
|
|
|
return // we're using the fact that once one OR is true, the rest is skipped
|
|
|
|
HTMLPurifier_Bootstrap::autoload($class) ||
|
|
|
|
HTMLPurifierExtras::autoload($class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize and load alternative classes
|
|
|
|
require_once '../extras/HTMLPurifierExtras.auto.php';
|
|
|
|
|
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
// initialize and load HTML Purifier
|
2007-07-30 16:56:50 +00:00
|
|
|
// use ?standalone to load the alterative standalone stub
|
2008-01-07 00:17:49 +00:00
|
|
|
if ($AC['standalone']) {
|
2008-01-27 01:54:41 +00:00
|
|
|
set_include_path(realpath('../library/standalone') . PATH_SEPARATOR . realpath('blanks') . PATH_SEPARATOR . get_include_path());
|
2007-07-30 16:56:50 +00:00
|
|
|
require_once '../library/HTMLPurifier.standalone.php';
|
|
|
|
} else {
|
2008-01-27 01:54:41 +00:00
|
|
|
set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path() );
|
2008-02-10 21:34:52 +00:00
|
|
|
require_once 'HTMLPurifier.auto.php';
|
2008-02-10 22:51:33 +00:00
|
|
|
require_once 'HTMLPurifier.includes.php';
|
2007-07-30 16:56:50 +00:00
|
|
|
}
|
2007-08-02 01:12:27 +00:00
|
|
|
require_once 'HTMLPurifier/Harness.php';
|
2006-08-11 20:23:41 +00:00
|
|
|
|
2007-05-29 20:21:33 +00:00
|
|
|
// setup special DefinitionCacheFactory decorator
|
|
|
|
$factory =& HTMLPurifier_DefinitionCacheFactory::instance();
|
|
|
|
$factory->addDecorator('Memory'); // since we deal with a lot of config objects
|
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
// load tests
|
2006-08-05 02:28:35 +00:00
|
|
|
$test_files = array();
|
2007-01-19 23:26:15 +00:00
|
|
|
require 'test_files.php'; // populates $test_files array
|
|
|
|
sort($test_files); // for the SELECT
|
|
|
|
$GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
|
2006-08-05 02:28:35 +00:00
|
|
|
$test_file_lookup = array_flip($test_files);
|
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
// determine test file
|
2008-01-07 00:17:49 +00:00
|
|
|
if ($AC['file']) {
|
|
|
|
if (!isset($test_file_lookup[$AC['file']])) {
|
|
|
|
echo "Invalid file passed\n";
|
|
|
|
exit;
|
|
|
|
}
|
2007-01-19 23:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
|
2008-01-07 00:17:49 +00:00
|
|
|
if ($AC['file']) {
|
2006-08-05 02:28:35 +00:00
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
$test = new TestSuite($AC['file']);
|
|
|
|
require_once $AC['file'];
|
|
|
|
$test->addTestClass(path2class($AC['file']));
|
2006-08-05 02:28:35 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
$standalone = '';
|
|
|
|
if ($AC['standalone']) $standalone = ' (standalone)';
|
|
|
|
$test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
|
2006-08-05 02:28:35 +00:00
|
|
|
foreach ($test_files as $test_file) {
|
2007-05-28 02:29:48 +00:00
|
|
|
require_once $test_file;
|
|
|
|
$test->addTestClass(path2class($test_file));
|
2006-08-05 02:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2006-08-01 00:18:22 +00:00
|
|
|
|
2008-01-21 19:27:55 +00:00
|
|
|
if ($AC['dry']) $reporter->makeDry();
|
|
|
|
|
2006-08-01 00:18:22 +00:00
|
|
|
$test->run($reporter);
|