2006-07-23 00:11:03 +00:00
|
|
|
<?php
|
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
/** @file
|
|
|
|
* Unit tester
|
2008-12-06 07:28:20 +00:00
|
|
|
*
|
2008-01-07 00:17:49 +00:00
|
|
|
* 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-07-05 06:25:40 +00:00
|
|
|
* - type, the type of tests to run, can be 'htmlpurifier', 'configdoc',
|
|
|
|
* 'fstools', 'htmlt', 'vtest' or 'phpt'
|
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
|
|
|
|
2010-05-21 01:50:44 +00:00
|
|
|
// HTML Purifier runs error free on E_STRICT, so if code reports
|
|
|
|
// errors, we want to know about it.
|
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
|
|
|
|
|
|
// Because we always want to know about errors, and because SimpleTest
|
|
|
|
// will notify us about them, logging the errors to stderr is
|
|
|
|
// counterproductive and in fact the wrong thing when a test case
|
|
|
|
// exercises an error condition to detect for it.
|
|
|
|
ini_set('log_errors', false);
|
|
|
|
|
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-04-15 03:33:09 +00:00
|
|
|
$php = 'php'; // for safety
|
2008-06-10 00:13:44 +00:00
|
|
|
ini_set('memory_limit', '64M');
|
2008-04-15 03:33:09 +00:00
|
|
|
|
2008-02-17 18:21:45 +00:00
|
|
|
require 'common.php';
|
2008-01-07 00:17:49 +00:00
|
|
|
$AC = array(); // parameters
|
|
|
|
$AC['flush'] = false;
|
|
|
|
$AC['standalone'] = false;
|
|
|
|
$AC['file'] = '';
|
2008-10-24 16:50:59 +00:00
|
|
|
$AC['xml'] = false;
|
|
|
|
$AC['dry'] = false;
|
|
|
|
$AC['php'] = $php;
|
|
|
|
$AC['help'] = false;
|
2008-11-24 01:45:21 +00:00
|
|
|
$AC['verbose'] = false;
|
2009-02-16 07:59:33 +00:00
|
|
|
$AC['txt'] = false;
|
2008-02-16 05:40:59 +00:00
|
|
|
|
2008-07-05 06:25:40 +00:00
|
|
|
$AC['type'] = '';
|
2008-02-16 05:40:59 +00:00
|
|
|
$AC['disable-phpt'] = false;
|
2008-07-05 06:25:40 +00:00
|
|
|
$AC['only-phpt'] = false; // alias for --type=phpt
|
2008-02-16 05:40:59 +00:00
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
$aliases = array(
|
|
|
|
'f' => 'file',
|
2008-11-24 01:45:21 +00:00
|
|
|
'h' => 'help',
|
|
|
|
'v' => 'verbose',
|
2008-01-07 00:17:49 +00:00
|
|
|
);
|
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-10-24 16:50:59 +00:00
|
|
|
if ($AC['help']) {
|
|
|
|
?>HTML Purifier test suite
|
|
|
|
Allowed options:
|
|
|
|
--flush
|
|
|
|
--standalone
|
|
|
|
--file (-f) HTMLPurifier/NameOfTest.php
|
|
|
|
--xml
|
2009-02-16 07:59:33 +00:00
|
|
|
--txt
|
2008-10-24 16:50:59 +00:00
|
|
|
--dry
|
|
|
|
--php /path/to/php
|
|
|
|
--type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt )
|
|
|
|
--disable-phpt
|
2008-11-24 01:45:21 +00:00
|
|
|
--verbose (-v)
|
2008-10-24 16:50:59 +00:00
|
|
|
<?php
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2008-02-18 03:48:07 +00:00
|
|
|
// Disable PHPT tests if they're not enabled
|
2008-07-05 06:25:40 +00:00
|
|
|
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
|
|
|
|
$AC['disable-phpt'] = true;
|
|
|
|
} elseif (!$AC['type'] && $AC['only-phpt']) {
|
|
|
|
// backwards-compat
|
|
|
|
$AC['type'] = 'phpt';
|
|
|
|
}
|
2008-02-18 03:48:07 +00:00
|
|
|
|
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-12-05 20:50:59 +00:00
|
|
|
// initialize and load HTML Purifier
|
|
|
|
// use ?standalone to load the alterative standalone stub
|
|
|
|
if ($AC['standalone']) {
|
|
|
|
require '../library/HTMLPurifier.standalone.php';
|
|
|
|
} else {
|
|
|
|
require '../library/HTMLPurifier.path.php';
|
|
|
|
require 'HTMLPurifier.includes.php';
|
|
|
|
}
|
|
|
|
require '../library/HTMLPurifier.autoload.php';
|
|
|
|
require 'HTMLPurifier/Harness.php';
|
|
|
|
|
2012-01-18 23:10:16 +00:00
|
|
|
// immediately load external libraries, so we can bail out early if
|
|
|
|
// they're bad
|
|
|
|
if ($GLOBALS['HTMLPurifierTest']['PEAR']) {
|
|
|
|
if ($GLOBALS['HTMLPurifierTest']['Net_IDNA2']) {
|
|
|
|
require_once 'Net/IDNA2.php';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2009-02-16 07:59:33 +00:00
|
|
|
} elseif (SimpleReporter::inCli() || $AC['txt']) {
|
|
|
|
if (!SimpleReporter::inCli()) header('Content-Type: text/plain;charset=UTF-8');
|
2008-11-24 01:45:21 +00:00
|
|
|
$reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
|
2008-04-03 21:24:16 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
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
|
2008-04-23 02:40:17 +00:00
|
|
|
$factory = HTMLPurifier_DefinitionCacheFactory::instance();
|
2007-05-29 20:21:33 +00:00
|
|
|
$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-07-05 06:25:40 +00:00
|
|
|
require 'test_files.php';
|
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);
|
2008-12-06 07:28:20 +00:00
|
|
|
if (isset($test_dirs_exclude[$file])) continue;
|
2008-03-02 02:05:47 +00:00
|
|
|
$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
|
|
|
|
2008-07-05 06:25:40 +00:00
|
|
|
// handle htmlt dirs
|
|
|
|
foreach ($htmlt_dirs as $dir) {
|
|
|
|
$htmlt_files = $FS->globr($dir, '*.htmlt');
|
|
|
|
foreach ($htmlt_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']) {
|
2008-12-06 07:28:20 +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']);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-05 02:28:35 +00:00
|
|
|
} else {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 09:24:59 +00:00
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|