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
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');
34 $AC = array(); // parameters
36 $AC['standalone'] = false;
42 $AC['verbose'] = false;
46 $AC['disable-phpt'] = false;
47 $AC['only-phpt'] = false; // alias for --type=phpt
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);
60 ?
>HTML Purifier test suite
64 --file (-f
) HTMLPurifier
/NameOfTest
.php
69 --type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt
)
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']) {
84 if (!SimpleReporter
::inCli()) {
85 // Undo any dangerous parameters
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';
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
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);
109 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
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'];
128 require 'test_files.php';
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;
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);
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);
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
173 if (!isset($test_file_lookup[$AC['file']])) {
174 echo "Invalid file passed\n";
181 $test = new TestSuite($AC['file']);
182 htmlpurifier_add_test($test, $AC['file']);
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