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 // HTML Purifier runs error free on E_STRICT, so if code reports
27 // errors, we want to know about it.
28 error_reporting(E_ALL | E_STRICT
);
30 // Because we always want to know about errors, and because SimpleTest
31 // will notify us about them, logging the errors to stderr is
32 // counterproductive and in fact the wrong thing when a test case
33 // exercises an error condition to detect for it.
34 ini_set('log_errors', false);
36 define('HTMLPurifierTest', 1);
37 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
38 chdir(dirname(__FILE__
));
40 $php = 'php'; // for safety
41 ini_set('memory_limit', '64M');
44 $AC = array(); // parameters
46 $AC['standalone'] = false;
52 $AC['verbose'] = false;
56 $AC['disable-phpt'] = false;
57 $AC['only-phpt'] = false; // alias for --type=phpt
65 // It's important that this does not call the autoloader. Not a problem
66 // with a function, but could be if we put this in a class.
67 htmlpurifier_parse_args($AC, $aliases);
70 ?
>HTML Purifier test suite
74 --file (-f
) HTMLPurifier
/NameOfTest
.php
79 --type ( htmlpurifier | configdoc | fstools | htmlt | vtest | phpt
)
86 // Disable PHPT tests if they're not enabled
87 if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
88 $AC['disable-phpt'] = true;
89 } elseif (!$AC['type'] && $AC['only-phpt']) {
94 if (!SimpleReporter
::inCli()) {
95 // Undo any dangerous parameters
99 // initialize and load HTML Purifier
100 // use ?standalone to load the alterative standalone stub
101 if ($AC['standalone']) {
102 require '../library/HTMLPurifier.standalone.php';
104 require '../library/HTMLPurifier.path.php';
105 require 'HTMLPurifier.includes.php';
107 require '../library/HTMLPurifier.autoload.php';
108 require 'HTMLPurifier/Harness.php';
110 // immediately load external libraries, so we can bail out early if
112 if ($GLOBALS['HTMLPurifierTest']['PEAR']) {
113 if ($GLOBALS['HTMLPurifierTest']['Net_IDNA2']) {
114 require_once 'Net/IDNA2.php';
118 // Shell-script code is executed
121 if (!SimpleReporter
::inCli()) header('Content-Type: text/xml;charset=UTF-8');
122 $reporter = new XmlReporter();
123 } elseif (SimpleReporter
::inCli() ||
$AC['txt']) {
124 if (!SimpleReporter
::inCli()) header('Content-Type: text/plain;charset=UTF-8');
125 $reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
127 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
131 htmlpurifier_flush($AC['php'], $reporter);
134 // Now, userland code begins to be executed
136 // setup special DefinitionCacheFactory decorator
137 $factory = HTMLPurifier_DefinitionCacheFactory
::instance();
138 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
140 if (!$AC['disable-phpt']) {
141 $phpt = PHPT_Registry
::getInstance();
142 $phpt->php
= $AC['php'];
146 require 'test_files.php';
151 foreach ($test_dirs as $dir) {
152 $raw_files = $FS->globr($dir, '*Test.php');
153 foreach ($raw_files as $file) {
154 $file = str_replace('\\', '/', $file);
155 if (isset($test_dirs_exclude[$file])) continue;
156 $test_files[] = $file;
161 foreach ($vtest_dirs as $dir) {
162 $raw_files = $FS->globr($dir, '*.vtest');
163 foreach ($raw_files as $file) {
164 $test_files[] = str_replace('\\', '/', $file);
169 foreach ($phpt_dirs as $dir) {
170 $phpt_files = $FS->globr($dir, '*.phpt');
171 foreach ($phpt_files as $file) {
172 $test_files[] = str_replace('\\', '/', $file);
177 foreach ($htmlt_dirs as $dir) {
178 $htmlt_files = $FS->globr($dir, '*.htmlt');
179 foreach ($htmlt_files as $file) {
180 $test_files[] = str_replace('\\', '/', $file);
184 array_unique($test_files);
185 sort($test_files); // for the SELECT
186 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
187 $test_file_lookup = array_flip($test_files);
189 // determine test file
191 if (!isset($test_file_lookup[$AC['file']])) {
192 echo "Invalid file passed\n";
199 $test = new TestSuite($AC['file']);
200 htmlpurifier_add_test($test, $AC['file']);
205 if ($AC['standalone']) $standalone = ' (standalone)';
206 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION
. $standalone);
207 foreach ($test_files as $test_file) {
208 htmlpurifier_add_test($test, $test_file);
213 if ($AC['dry']) $reporter->makeDry();
215 $result = $test->run($reporter);
220 exit(1); // Abject failure.
223 // vim: et sw=4 sts=4