Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / tests / index.php
blob0c8c4e1a8e9789657bb52bef47cc0b352c33f0e9
1 <?php
3 /** @file
4 * Unit tester
6 * The heart and soul of HTML Purifier's correctness; anything and everything
7 * is tested here! Arguments are specified like --arg=opt, allowed arguments
8 * are:
9 * - flush, whether or not to flush definition caches before running
10 * - standalone, whether or not to test the standalone version
11 * - file (f), a single file to test
12 * - xml, whether or not to output XML
13 * - dry, whether or not to do a dry run
14 * - type, the type of tests to run, can be 'htmlpurifier', 'configdoc',
15 * 'fstools', 'htmlt', 'vtest' or 'phpt'
17 * If you're interested in running the test-cases, mosey over to
18 * ../test-settings.sample.php, copy the file to test-settings.php and follow
19 * the enclosed instructions.
21 * @warning File setup does not exactly match with autoloader; make sure that
22 * non-test classes (i.e. classes that are not retrieved using
23 * $test_files) do not have underscores in their names.
26 define('HTMLPurifierTest', 1);
27 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
28 chdir(dirname(__FILE__));
30 $php = 'php'; // for safety
31 ini_set('memory_limit', '64M');
33 require 'common.php';
34 $AC = array(); // parameters
35 $AC['flush'] = false;
36 $AC['standalone'] = false;
37 $AC['file'] = '';
38 $AC['xml'] = false;
39 $AC['dry'] = false;
40 $AC['php'] = $php;
41 $AC['help'] = false;
42 $AC['verbose'] = false;
43 $AC['txt'] = false;
45 $AC['type'] = '';
46 $AC['disable-phpt'] = false;
47 $AC['only-phpt'] = false; // alias for --type=phpt
49 $aliases = array(
50 'f' => 'file',
51 'h' => 'help',
52 'v' => 'verbose',
55 // It's important that this does not call the autoloader. Not a problem
56 // with a function, but could be if we put this in a class.
57 htmlpurifier_parse_args($AC, $aliases);
59 if ($AC['help']) {
60 ?>HTML Purifier test suite
61 Allowed options:
62 --flush
63 --standalone
64 --file (-f) HTMLPurifier/NameOfTest.php
65 --xml
66 --txt
67 --dry
68 --php /path/to/php
69 --type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt )
70 --disable-phpt
71 --verbose (-v)
72 <?php
73 exit;
76 // Disable PHPT tests if they're not enabled
77 if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
78 $AC['disable-phpt'] = true;
79 } elseif (!$AC['type'] && $AC['only-phpt']) {
80 // backwards-compat
81 $AC['type'] = 'phpt';
84 if (!SimpleReporter::inCli()) {
85 // Undo any dangerous parameters
86 $AC['php'] = $php;
89 // initialize and load HTML Purifier
90 // use ?standalone to load the alterative standalone stub
91 if ($AC['standalone']) {
92 require '../library/HTMLPurifier.standalone.php';
93 } else {
94 require '../library/HTMLPurifier.path.php';
95 require 'HTMLPurifier.includes.php';
97 require '../library/HTMLPurifier.autoload.php';
98 require 'HTMLPurifier/Harness.php';
100 // Shell-script code is executed
102 if ($AC['xml']) {
103 if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
104 $reporter = new XmlReporter();
105 } elseif (SimpleReporter::inCli() || $AC['txt']) {
106 if (!SimpleReporter::inCli()) header('Content-Type: text/plain;charset=UTF-8');
107 $reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
108 } else {
109 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
112 if ($AC['flush']) {
113 htmlpurifier_flush($AC['php'], $reporter);
116 // Now, userland code begins to be executed
118 // setup special DefinitionCacheFactory decorator
119 $factory = HTMLPurifier_DefinitionCacheFactory::instance();
120 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
122 if (!$AC['disable-phpt']) {
123 $phpt = PHPT_Registry::getInstance();
124 $phpt->php = $AC['php'];
127 // load tests
128 require 'test_files.php';
130 $FS = new FSTools();
132 // handle test dirs
133 foreach ($test_dirs as $dir) {
134 $raw_files = $FS->globr($dir, '*Test.php');
135 foreach ($raw_files as $file) {
136 $file = str_replace('\\', '/', $file);
137 if (isset($test_dirs_exclude[$file])) continue;
138 $test_files[] = $file;
142 // handle vtest dirs
143 foreach ($vtest_dirs as $dir) {
144 $raw_files = $FS->globr($dir, '*.vtest');
145 foreach ($raw_files as $file) {
146 $test_files[] = str_replace('\\', '/', $file);
150 // handle phpt files
151 foreach ($phpt_dirs as $dir) {
152 $phpt_files = $FS->globr($dir, '*.phpt');
153 foreach ($phpt_files as $file) {
154 $test_files[] = str_replace('\\', '/', $file);
158 // handle htmlt dirs
159 foreach ($htmlt_dirs as $dir) {
160 $htmlt_files = $FS->globr($dir, '*.htmlt');
161 foreach ($htmlt_files as $file) {
162 $test_files[] = str_replace('\\', '/', $file);
166 array_unique($test_files);
167 sort($test_files); // for the SELECT
168 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
169 $test_file_lookup = array_flip($test_files);
171 // determine test file
172 if ($AC['file']) {
173 if (!isset($test_file_lookup[$AC['file']])) {
174 echo "Invalid file passed\n";
175 exit;
179 if ($AC['file']) {
181 $test = new TestSuite($AC['file']);
182 htmlpurifier_add_test($test, $AC['file']);
184 } else {
186 $standalone = '';
187 if ($AC['standalone']) $standalone = ' (standalone)';
188 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
189 foreach ($test_files as $test_file) {
190 htmlpurifier_add_test($test, $test_file);
195 if ($AC['dry']) $reporter->makeDry();
197 $test->run($reporter);
199 // vim: et sw=4 sts=4