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-02-18 04:41:42 +00:00
|
|
|
*
|
2008-04-10 02:56:46 +00:00
|
|
|
* If you're interested in running the test-cases, mosey over to
|
|
|
|
* ../test-settings.sample.php, copy the file to test-settings.php and follow
|
|
|
|
* the enclosed instructions.
|
|
|
|
*
|
2008-02-18 04:41:42 +00:00
|
|
|
* @warning File setup does not exactly match with autoloader; make sure that
|
|
|
|
* non-test classes (i.e. classes that are not retrieved using
|
|
|
|
* $test_files) do not have underscores in their names.
|
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-02-17 18:21:45 +00:00
|
|
|
require '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-02-16 00:40:30 +00:00
|
|
|
$AC['php'] = 'php';
|
2008-02-16 05:40:59 +00:00
|
|
|
|
|
|
|
// Convenience parameters for running quicker tests; ideally all tests
|
|
|
|
// should be performed.
|
|
|
|
$AC['disable-phpt'] = false;
|
|
|
|
$AC['only-phpt'] = false;
|
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
$aliases = array(
|
|
|
|
'f' => 'file',
|
|
|
|
);
|
2008-02-17 23:59:23 +00:00
|
|
|
|
|
|
|
// It's important that this does not call the autoloader. Not a problem
|
|
|
|
// with a function, but could be if we put this in a class.
|
2008-01-07 00:17:49 +00:00
|
|
|
htmlpurifier_parse_args($AC, $aliases);
|
|
|
|
|
2008-02-18 03:48:07 +00:00
|
|
|
// Disable PHPT tests if they're not enabled
|
|
|
|
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) $AC['disable-phpt'] = true;
|
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
if (!SimpleReporter::inCli()) {
|
|
|
|
// Undo any dangerous parameters
|
2008-02-16 23:23:45 +00:00
|
|
|
$AC['php'] = $php;
|
2008-01-27 05:31:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-16 05:40:59 +00:00
|
|
|
if ($AC['disable-phpt'] && $AC['only-phpt']) {
|
|
|
|
echo "Cannot disable and allow only PHPT tests!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-03-04 04:20:55 +00:00
|
|
|
// Shell-script code is executed
|
|
|
|
|
2008-04-03 21:24:16 +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);
|
|
|
|
}
|
|
|
|
|
2008-03-04 04:20:55 +00:00
|
|
|
if ($AC['flush']) {
|
2008-04-03 21:24:16 +00:00
|
|
|
htmlpurifier_flush($AC['php'], $reporter);
|
2008-03-04 04:20:55 +00:00
|
|
|
}
|
|
|
|
|
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-02-17 18:21:45 +00:00
|
|
|
require '../library/HTMLPurifier.standalone.php';
|
2007-07-30 16:56:50 +00:00
|
|
|
} else {
|
2008-02-17 18:21:45 +00:00
|
|
|
require '../library/HTMLPurifier.path.php';
|
|
|
|
require 'HTMLPurifier.includes.php';
|
|
|
|
require '../library/HTMLPurifier.autoload.php';
|
2007-07-30 16:56:50 +00:00
|
|
|
}
|
2008-02-17 18:21:45 +00:00
|
|
|
require 'HTMLPurifier/Harness.php';
|
2006-08-11 20:23:41 +00:00
|
|
|
|
2008-02-17 23:59:23 +00:00
|
|
|
// Now, userland code begins to be executed
|
|
|
|
|
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
|
|
|
|
|
2008-02-17 23:59:23 +00:00
|
|
|
if (!$AC['disable-phpt']) {
|
|
|
|
$phpt = PHPT_Registry::getInstance();
|
|
|
|
$phpt->php = $AC['php'];
|
|
|
|
}
|
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
// load tests
|
2008-03-02 02:05:47 +00:00
|
|
|
|
2006-08-05 02:28:35 +00:00
|
|
|
$test_files = array();
|
2008-03-02 02:05:47 +00:00
|
|
|
$test_dirs = array();
|
|
|
|
$test_dirs_exclude = array();
|
2008-03-23 02:51:50 +00:00
|
|
|
$vtest_dirs = array();
|
2008-02-17 23:59:23 +00:00
|
|
|
$phpt_dirs = array();
|
2008-03-02 02:05:47 +00:00
|
|
|
|
2007-01-19 23:26:15 +00:00
|
|
|
require 'test_files.php'; // populates $test_files array
|
2008-03-02 02:05:47 +00:00
|
|
|
|
|
|
|
$FS = new FSTools();
|
|
|
|
|
|
|
|
// handle test dirs
|
|
|
|
foreach ($test_dirs as $dir) {
|
|
|
|
$raw_files = $FS->globr($dir, '*Test.php');
|
|
|
|
foreach ($raw_files as $file) {
|
|
|
|
$file = str_replace('\\', '/', $file);
|
|
|
|
if (isset($test_dirs_exclude[$file])) continue;
|
|
|
|
$test_files[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 01:06:35 +00:00
|
|
|
// handle vtest dirs
|
|
|
|
foreach ($vtest_dirs as $dir) {
|
|
|
|
$raw_files = $FS->globr($dir, '*.vtest');
|
|
|
|
foreach ($raw_files as $file) {
|
|
|
|
$test_files[] = str_replace('\\', '/', $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-17 23:59:23 +00:00
|
|
|
// handle phpt files
|
|
|
|
foreach ($phpt_dirs as $dir) {
|
|
|
|
$phpt_files = $FS->globr($dir, '*.phpt');
|
|
|
|
foreach ($phpt_files as $file) {
|
|
|
|
$test_files[] = str_replace('\\', '/', $file);
|
|
|
|
}
|
|
|
|
}
|
2008-03-02 02:05:47 +00:00
|
|
|
|
|
|
|
array_unique($test_files);
|
2007-01-19 23:26:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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']);
|
2008-02-16 00:40:30 +00:00
|
|
|
htmlpurifier_add_test($test, $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) {
|
2008-02-16 00:40:30 +00:00
|
|
|
htmlpurifier_add_test($test, $test_file);
|
2006-08-05 02:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-07-23 00:11:03 +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);
|