2008-01-06 19:31:21 +00:00
|
|
|
<?php
|
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
if (!defined('HTMLPurifierTest')) {
|
|
|
|
echo "Invalid entry point\n";
|
|
|
|
exit;
|
|
|
|
}
|
2008-01-06 19:31:21 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
// setup our own autoload, checking for HTMLPurifier library if spl_autoload_register
|
|
|
|
// is not allowed
|
|
|
|
function __autoload($class) {
|
|
|
|
if (!function_exists('spl_autoload_register')) {
|
2008-02-17 23:59:23 +00:00
|
|
|
if (HTMLPurifier_Bootstrap::autoload($class)) return true;
|
|
|
|
if (HTMLPurifierExtras::autoload($class)) return true;
|
2008-02-16 00:40:30 +00:00
|
|
|
}
|
2008-02-17 18:21:45 +00:00
|
|
|
require str_replace('_', '/', $class) . '.php';
|
2008-02-16 00:40:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (function_exists('spl_autoload_register')) {
|
|
|
|
spl_autoload_register('__autoload');
|
|
|
|
}
|
|
|
|
|
2008-01-06 19:31:21 +00:00
|
|
|
// default settings (protect against register_globals)
|
|
|
|
$GLOBALS['HTMLPurifierTest'] = array();
|
|
|
|
$GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
|
2008-02-18 03:48:07 +00:00
|
|
|
$GLOBALS['HTMLPurifierTest']['PHPT'] = true; // do PHPT tests
|
2008-01-06 19:31:21 +00:00
|
|
|
$GLOBALS['HTMLPurifierTest']['PH5P'] = class_exists('DOMDocument');
|
|
|
|
|
|
|
|
// default library settings
|
|
|
|
$simpletest_location = 'simpletest/'; // reasonable guess
|
|
|
|
$csstidy_location = false;
|
2008-01-07 00:17:49 +00:00
|
|
|
$versions_to_test = array();
|
2008-02-16 23:23:45 +00:00
|
|
|
$php = 'php';
|
2008-01-07 00:17:49 +00:00
|
|
|
$phpv = 'phpv';
|
2008-01-06 19:31:21 +00:00
|
|
|
|
|
|
|
// load configuration
|
|
|
|
if (file_exists('../conf/test-settings.php')) include '../conf/test-settings.php';
|
|
|
|
if (file_exists('../test-settings.php')) include '../test-settings.php';
|
|
|
|
|
|
|
|
// load SimpleTest
|
2008-02-17 18:21:45 +00:00
|
|
|
require $simpletest_location . 'unit_tester.php';
|
|
|
|
require $simpletest_location . 'reporter.php';
|
|
|
|
require $simpletest_location . 'mock_objects.php';
|
|
|
|
require $simpletest_location . 'xml.php';
|
|
|
|
require $simpletest_location . 'remote.php';
|
2008-01-06 19:31:21 +00:00
|
|
|
|
|
|
|
// load CSS Tidy
|
|
|
|
if ($csstidy_location !== false) {
|
2008-02-17 18:21:45 +00:00
|
|
|
require $csstidy_location . 'class.csstidy.php';
|
2008-01-06 19:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// load PEAR to include path
|
|
|
|
if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
|
|
|
|
// if PEAR is true, there's no need to add it to the path
|
|
|
|
set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR .
|
|
|
|
get_include_path());
|
|
|
|
}
|
|
|
|
|
|
|
|
// after external libraries are loaded, turn on compile time errors
|
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
|
|
|
2008-02-17 18:21:45 +00:00
|
|
|
// initialize extra HTML Purifier libraries
|
|
|
|
require '../extras/HTMLPurifierExtras.auto.php';
|
2008-02-16 18:03:51 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
// load SimpleTest addon functions
|
2008-02-17 18:21:45 +00:00
|
|
|
require 'generate_mock_once.func.php';
|
|
|
|
require 'path2class.func.php';
|
|
|
|
require 'tally_errors.func.php'; // compat
|
2008-01-06 19:31:21 +00:00
|
|
|
|
2008-01-07 00:17:49 +00:00
|
|
|
/**
|
|
|
|
* Arguments parser, is cli and web agnostic.
|
|
|
|
* @warning
|
|
|
|
* There are some quirks about the argument format:
|
2008-02-16 23:23:45 +00:00
|
|
|
* - Short boolean flags cannot be chained together
|
|
|
|
* - Only strings, integers and booleans are accepted
|
2008-01-07 00:17:49 +00:00
|
|
|
* @param $AC
|
|
|
|
* Arguments array to populate. This takes a simple format of 'argument'
|
|
|
|
* => default value. Depending on the type of the default value,
|
|
|
|
* arguments will be typecast accordingly. For example, if
|
|
|
|
* 'flag' => false is passed, all arguments for that will be cast to
|
|
|
|
* boolean. Do *not* pass null, as it will not be recognized.
|
|
|
|
* @param $aliases
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function htmlpurifier_parse_args(&$AC, $aliases) {
|
|
|
|
if (empty($_GET)) {
|
|
|
|
array_shift($_SERVER['argv']);
|
2008-02-16 23:23:45 +00:00
|
|
|
$o = false;
|
|
|
|
$bool = false;
|
|
|
|
$val_is_bool = false;
|
2008-01-07 00:17:49 +00:00
|
|
|
foreach ($_SERVER['argv'] as $opt) {
|
2008-02-16 23:23:45 +00:00
|
|
|
if ($o !== false) {
|
|
|
|
$v = $opt;
|
2008-01-07 00:17:49 +00:00
|
|
|
} else {
|
2008-02-16 23:23:45 +00:00
|
|
|
if ($opt === '') continue;
|
|
|
|
if (strlen($opt) > 2 && strncmp($opt, '--', 2) === 0) {
|
|
|
|
$o = substr($opt, 2);
|
|
|
|
} elseif ($opt[0] == '-') {
|
|
|
|
$o = substr($opt, 1);
|
|
|
|
} else {
|
|
|
|
$lopt = strtolower($opt);
|
|
|
|
if ($bool !== false && ($opt === '0' || $lopt === 'off' || $lopt === 'no')) {
|
|
|
|
$o = $bool;
|
|
|
|
$v = false;
|
|
|
|
$val_is_bool = true;
|
|
|
|
} elseif (isset($aliases[''])) {
|
|
|
|
$o = $aliases[''];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bool = false;
|
|
|
|
if (!isset($AC[$o]) || !is_bool($AC[$o])) {
|
|
|
|
if (strpos($o, '=') === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list($o, $v) = explode('=', $o);
|
|
|
|
} elseif (!$val_is_bool) {
|
|
|
|
$v = true;
|
|
|
|
$bool = $o;
|
|
|
|
}
|
|
|
|
$val_is_bool = false;
|
2008-01-07 00:17:49 +00:00
|
|
|
}
|
2008-02-16 23:23:45 +00:00
|
|
|
if ($o === false) continue;
|
2008-01-07 00:17:49 +00:00
|
|
|
htmlpurifier_args($AC, $aliases, $o, $v);
|
2008-02-16 23:23:45 +00:00
|
|
|
$o = false;
|
2008-01-07 00:17:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach ($_GET as $o => $v) {
|
|
|
|
if (get_magic_quotes_gpc()) $v = stripslashes($v);
|
|
|
|
htmlpurifier_args($AC, $aliases, $o, $v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually performs assignment to $AC, see htmlpurifier_parse_args()
|
|
|
|
* @param $AC Arguments array to write to
|
|
|
|
* @param $aliases Aliases for options
|
|
|
|
* @param $o Argument name
|
|
|
|
* @param $v Argument value
|
|
|
|
*/
|
|
|
|
function htmlpurifier_args(&$AC, $aliases, $o, $v) {
|
|
|
|
if (isset($aliases[$o])) $o = $aliases[$o];
|
|
|
|
if (!isset($AC[$o])) return;
|
|
|
|
if (is_string($AC[$o])) $AC[$o] = $v;
|
2008-02-17 01:07:17 +00:00
|
|
|
if (is_bool($AC[$o])) $AC[$o] = ($v === '') ? true :(bool) $v;
|
2008-02-16 23:23:45 +00:00
|
|
|
if (is_int($AC[$o])) $AC[$o] = (int) $v;
|
2008-01-07 00:17:49 +00:00
|
|
|
}
|
2008-02-16 00:40:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a test-class; depending on the file's extension this may involve
|
|
|
|
* a regular UnitTestCase or a special PHPT test
|
|
|
|
*/
|
2008-02-16 05:40:59 +00:00
|
|
|
function htmlpurifier_add_test($test, $test_file, $only_phpt = false) {
|
|
|
|
switch (strrchr($test_file, ".")) {
|
|
|
|
case '.phpt':
|
|
|
|
return $test->addTestCase(new PHPT_Controller_SimpleTest($test_file));
|
|
|
|
case '.php':
|
|
|
|
require_once $test_file;
|
|
|
|
return $test->addTestClass(path2class($test_file));
|
|
|
|
default:
|
|
|
|
trigger_error("$test_file is an invalid file for testing", E_USER_ERROR);
|
2008-02-16 00:40:30 +00:00
|
|
|
}
|
|
|
|
}
|