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');
35 $AC = array(); // parameters
37 $AC['standalone'] = false;
44 $AC['disable-phpt'] = false;
45 $AC['only-phpt'] = false; // alias for --type=phpt
51 // It's important that this does not call the autoloader. Not a problem
52 // with a function, but could be if we put this in a class.
53 htmlpurifier_parse_args($AC, $aliases);
55 // Disable PHPT tests if they're not enabled
56 if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
57 $AC['disable-phpt'] = true;
58 } elseif (!$AC['type'] && $AC['only-phpt']) {
63 if (!SimpleReporter
::inCli()) {
64 // Undo any dangerous parameters
68 // Shell-script code is executed
71 if (!SimpleReporter
::inCli()) header('Content-Type: text/xml;charset=UTF-8');
72 $reporter = new XmlReporter();
73 } elseif (SimpleReporter
::inCli()) {
74 $reporter = new TextReporter();
76 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
80 htmlpurifier_flush($AC['php'], $reporter);
83 // initialize and load HTML Purifier
84 // use ?standalone to load the alterative standalone stub
85 if ($AC['standalone']) {
86 require '../library/HTMLPurifier.standalone.php';
88 require '../library/HTMLPurifier.path.php';
89 require 'HTMLPurifier.includes.php';
91 require '../library/HTMLPurifier.autoload.php';
92 require 'HTMLPurifier/Harness.php';
94 // Now, userland code begins to be executed
96 // setup special DefinitionCacheFactory decorator
97 $factory = HTMLPurifier_DefinitionCacheFactory
::instance();
98 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
100 if (!$AC['disable-phpt']) {
101 $phpt = PHPT_Registry
::getInstance();
102 $phpt->php
= $AC['php'];
106 require 'test_files.php';
111 foreach ($test_dirs as $dir) {
112 $raw_files = $FS->globr($dir, '*Test.php');
113 foreach ($raw_files as $file) {
114 $file = str_replace('\\', '/', $file);
115 if (isset($test_dirs_exclude[$file])) continue;
116 $test_files[] = $file;
121 foreach ($vtest_dirs as $dir) {
122 $raw_files = $FS->globr($dir, '*.vtest');
123 foreach ($raw_files as $file) {
124 $test_files[] = str_replace('\\', '/', $file);
129 foreach ($phpt_dirs as $dir) {
130 $phpt_files = $FS->globr($dir, '*.phpt');
131 foreach ($phpt_files as $file) {
132 $test_files[] = str_replace('\\', '/', $file);
137 foreach ($htmlt_dirs as $dir) {
138 $htmlt_files = $FS->globr($dir, '*.htmlt');
139 foreach ($htmlt_files as $file) {
140 $test_files[] = str_replace('\\', '/', $file);
144 array_unique($test_files);
145 sort($test_files); // for the SELECT
146 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
147 $test_file_lookup = array_flip($test_files);
149 // determine test file
151 if (!isset($test_file_lookup[$AC['file']])) {
152 echo "Invalid file passed\n";
159 $test = new TestSuite($AC['file']);
160 htmlpurifier_add_test($test, $AC['file']);
165 if ($AC['standalone']) $standalone = ' (standalone)';
166 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION
. $standalone);
167 foreach ($test_files as $test_file) {
168 htmlpurifier_add_test($test, $test_file);
173 if ($AC['dry']) $reporter->makeDry();
175 $test->run($reporter);