7 * The heart and soul of HTML Purifier's correctness; anything and everything
8 * is tested here! Arguments are specified like --arg=opt, allowed arguments
10 * - flush, whether or not to flush definition caches before running
11 * - standalone, whether or not to test the standalone version
12 * - file (f), a single file to test
13 * - xml, whether or not to output XML
14 * - dry, whether or not to do a dry run
15 * - type, the type of tests to run, can be 'htmlpurifier', 'configdoc',
16 * 'fstools', 'htmlt', 'vtest' or 'phpt'
18 * If you're interested in running the test-cases, mosey over to
19 * ../test-settings.sample.php, copy the file to test-settings.php and follow
20 * the enclosed instructions.
22 * @warning File setup does not exactly match with autoloader; make sure that
23 * non-test classes (i.e. classes that are not retrieved using
24 * $test_files) do not have underscores in their names.
27 define('HTMLPurifierTest', 1);
28 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
29 chdir(dirname(__FILE__
));
31 $php = 'php'; // for safety
32 ini_set('memory_limit', '64M');
35 $AC = array(); // parameters
37 $AC['standalone'] = false;
43 $AC['verbose'] = false;
47 $AC['disable-phpt'] = false;
48 $AC['only-phpt'] = false; // alias for --type=phpt
56 // It's important that this does not call the autoloader. Not a problem
57 // with a function, but could be if we put this in a class.
58 htmlpurifier_parse_args($AC, $aliases);
61 ?
>HTML Purifier test suite
65 --file (-f
) HTMLPurifier
/NameOfTest
.php
70 --type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt
)
77 // Disable PHPT tests if they're not enabled
78 if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
79 $AC['disable-phpt'] = true;
80 } elseif (!$AC['type'] && $AC['only-phpt']) {
85 if (!SimpleReporter
::inCli()) {
86 // Undo any dangerous parameters
90 // initialize and load HTML Purifier
91 // use ?standalone to load the alterative standalone stub
92 if ($AC['standalone']) {
93 require '../library/HTMLPurifier.standalone.php';
95 require '../library/HTMLPurifier.path.php';
96 require 'HTMLPurifier.includes.php';
98 require '../library/HTMLPurifier.autoload.php';
99 require 'HTMLPurifier/Harness.php';
101 // Shell-script code is executed
104 if (!SimpleReporter
::inCli()) header('Content-Type: text/xml;charset=UTF-8');
105 $reporter = new XmlReporter();
106 } elseif (SimpleReporter
::inCli() ||
$AC['txt']) {
107 if (!SimpleReporter
::inCli()) header('Content-Type: text/plain;charset=UTF-8');
108 $reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
110 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
114 htmlpurifier_flush($AC['php'], $reporter);
117 // Now, userland code begins to be executed
119 // setup special DefinitionCacheFactory decorator
120 $factory = HTMLPurifier_DefinitionCacheFactory
::instance();
121 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
123 if (!$AC['disable-phpt']) {
124 $phpt = PHPT_Registry
::getInstance();
125 $phpt->php
= $AC['php'];
129 require 'test_files.php';
134 foreach ($test_dirs as $dir) {
135 $raw_files = $FS->globr($dir, '*Test.php');
136 foreach ($raw_files as $file) {
137 $file = str_replace('\\', '/', $file);
138 if (isset($test_dirs_exclude[$file])) continue;
139 $test_files[] = $file;
144 foreach ($vtest_dirs as $dir) {
145 $raw_files = $FS->globr($dir, '*.vtest');
146 foreach ($raw_files as $file) {
147 $test_files[] = str_replace('\\', '/', $file);
152 foreach ($phpt_dirs as $dir) {
153 $phpt_files = $FS->globr($dir, '*.phpt');
154 foreach ($phpt_files as $file) {
155 $test_files[] = str_replace('\\', '/', $file);
160 foreach ($htmlt_dirs as $dir) {
161 $htmlt_files = $FS->globr($dir, '*.htmlt');
162 foreach ($htmlt_files as $file) {
163 $test_files[] = str_replace('\\', '/', $file);
167 array_unique($test_files);
168 sort($test_files); // for the SELECT
169 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
170 $test_file_lookup = array_flip($test_files);
172 // determine test file
174 if (!isset($test_file_lookup[$AC['file']])) {
175 echo "Invalid file passed\n";
182 $test = new TestSuite($AC['file']);
183 htmlpurifier_add_test($test, $AC['file']);
188 if ($AC['standalone']) $standalone = ' (standalone)';
189 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION
. $standalone);
190 foreach ($test_files as $test_file) {
191 htmlpurifier_add_test($test, $test_file);
196 if ($AC['dry']) $reporter->makeDry();
198 $test->run($reporter);
200 // vim: et sw=4 sts=4