Support for flashvars in HTML.SafeEmbed.
[htmlpurifier.git] / tests / index.php
blob5efe4a9a766455df178d978b1cd682f67fcbf6ea
1 #!/usr/bin/php
2 <?php
4 /** @file
5 * Unit tester
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
9 * are:
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');
34 require 'common.php';
35 $AC = array(); // parameters
36 $AC['flush'] = false;
37 $AC['standalone'] = false;
38 $AC['file'] = '';
39 $AC['xml'] = false;
40 $AC['dry'] = false;
41 $AC['php'] = $php;
42 $AC['help'] = false;
43 $AC['verbose'] = false;
44 $AC['txt'] = false;
46 $AC['type'] = '';
47 $AC['disable-phpt'] = false;
48 $AC['only-phpt'] = false; // alias for --type=phpt
50 $aliases = array(
51 'f' => 'file',
52 'h' => 'help',
53 'v' => 'verbose',
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);
60 if ($AC['help']) {
61 ?>HTML Purifier test suite
62 Allowed options:
63 --flush
64 --standalone
65 --file (-f) HTMLPurifier/NameOfTest.php
66 --xml
67 --txt
68 --dry
69 --php /path/to/php
70 --type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt )
71 --disable-phpt
72 --verbose (-v)
73 <?php
74 exit;
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']) {
81 // backwards-compat
82 $AC['type'] = 'phpt';
85 if (!SimpleReporter::inCli()) {
86 // Undo any dangerous parameters
87 $AC['php'] = $php;
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';
94 } else {
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
103 if ($AC['xml']) {
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);
109 } else {
110 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
113 if ($AC['flush']) {
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'];
128 // load tests
129 require 'test_files.php';
131 $FS = new FSTools();
133 // handle test dirs
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;
143 // handle vtest dirs
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);
151 // handle phpt files
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);
159 // handle htmlt dirs
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
173 if ($AC['file']) {
174 if (!isset($test_file_lookup[$AC['file']])) {
175 echo "Invalid file passed\n";
176 exit;
180 if ($AC['file']) {
182 $test = new TestSuite($AC['file']);
183 htmlpurifier_add_test($test, $AC['file']);
185 } else {
187 $standalone = '';
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