3 if (!defined('HTMLPurifierTest')) {
4 echo "Invalid entry point\n";
8 // setup our own autoload, checking for HTMLPurifier library if spl_autoload_register
10 function __autoload($class) {
11 if (!function_exists('spl_autoload_register')) {
12 if (HTMLPurifier_Bootstrap
::autoload($class)) return true;
13 if (HTMLPurifierExtras
::autoload($class)) return true;
15 require str_replace('_', '/', $class) . '.php';
18 if (function_exists('spl_autoload_register')) {
19 spl_autoload_register('__autoload');
22 // default settings (protect against register_globals)
23 $GLOBALS['HTMLPurifierTest'] = array();
24 $GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
25 $GLOBALS['HTMLPurifierTest']['PH5P'] = class_exists('DOMDocument');
27 // default library settings
28 $simpletest_location = 'simpletest/'; // reasonable guess
29 $csstidy_location = false;
30 $versions_to_test = array();
35 if (file_exists('../conf/test-settings.php')) include '../conf/test-settings.php';
36 if (file_exists('../test-settings.php')) include '../test-settings.php';
39 require $simpletest_location . 'unit_tester.php';
40 require $simpletest_location . 'reporter.php';
41 require $simpletest_location . 'mock_objects.php';
42 require $simpletest_location . 'xml.php';
43 require $simpletest_location . 'remote.php';
46 if ($csstidy_location !== false) {
47 require $csstidy_location . 'class.csstidy.php';
50 // load PEAR to include path
51 if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
52 // if PEAR is true, there's no need to add it to the path
53 set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR
.
57 // after external libraries are loaded, turn on compile time errors
58 error_reporting(E_ALL | E_STRICT
);
60 // initialize extra HTML Purifier libraries
61 require '../extras/HTMLPurifierExtras.auto.php';
63 // load SimpleTest addon functions
64 require 'generate_mock_once.func.php';
65 require 'path2class.func.php';
66 require 'tally_errors.func.php'; // compat
69 * Arguments parser, is cli and web agnostic.
71 * There are some quirks about the argument format:
72 * - Short boolean flags cannot be chained together
73 * - Only strings, integers and booleans are accepted
75 * Arguments array to populate. This takes a simple format of 'argument'
76 * => default value. Depending on the type of the default value,
77 * arguments will be typecast accordingly. For example, if
78 * 'flag' => false is passed, all arguments for that will be cast to
79 * boolean. Do *not* pass null, as it will not be recognized.
83 function htmlpurifier_parse_args(&$AC, $aliases) {
85 array_shift($_SERVER['argv']);
89 foreach ($_SERVER['argv'] as $opt) {
93 if ($opt === '') continue;
94 if (strlen($opt) > 2 && strncmp($opt, '--', 2) === 0) {
96 } elseif ($opt[0] == '-') {
99 $lopt = strtolower($opt);
100 if ($bool !== false && ($opt === '0' ||
$lopt === 'off' ||
$lopt === 'no')) {
104 } elseif (isset($aliases[''])) {
109 if (!isset($AC[$o]) ||
!is_bool($AC[$o])) {
110 if (strpos($o, '=') === false) {
113 list($o, $v) = explode('=', $o);
114 } elseif (!$val_is_bool) {
118 $val_is_bool = false;
120 if ($o === false) continue;
121 htmlpurifier_args($AC, $aliases, $o, $v);
125 foreach ($_GET as $o => $v) {
126 if (get_magic_quotes_gpc()) $v = stripslashes($v);
127 htmlpurifier_args($AC, $aliases, $o, $v);
133 * Actually performs assignment to $AC, see htmlpurifier_parse_args()
134 * @param $AC Arguments array to write to
135 * @param $aliases Aliases for options
136 * @param $o Argument name
137 * @param $v Argument value
139 function htmlpurifier_args(&$AC, $aliases, $o, $v) {
140 if (isset($aliases[$o])) $o = $aliases[$o];
141 if (!isset($AC[$o])) return;
142 if (is_string($AC[$o])) $AC[$o] = $v;
143 if (is_bool($AC[$o])) $AC[$o] = ($v === '') ?
true :(bool) $v;
144 if (is_int($AC[$o])) $AC[$o] = (int) $v;
148 * Adds a test-class; depending on the file's extension this may involve
149 * a regular UnitTestCase or a special PHPT test
151 function htmlpurifier_add_test($test, $test_file, $only_phpt = false) {
152 switch (strrchr($test_file, ".")) {
154 return $test->addTestCase(new PHPT_Controller_SimpleTest($test_file));
156 require_once $test_file;
157 return $test->addTestClass(path2class($test_file));
159 trigger_error("$test_file is an invalid file for testing", E_USER_ERROR
);