Add support for dry runs.
[htmlpurifier/bfroehle.git] / tests / index.php
blob5433f381787474cef6b14bacb618878b68e5fde9
1 <?php
3 /** @file
4 * Unit tester
5 *
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
15 define('HTMLPurifierTest', 1);
16 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
18 require_once 'common.php';
20 $AC = array(); // parameters
21 $AC['flush'] = false;
22 $AC['standalone'] = false;
23 $AC['file'] = '';
24 $AC['xml'] = false;
25 $AC['dry'] = false;
26 $aliases = array(
27 'f' => 'file',
29 htmlpurifier_parse_args($AC, $aliases);
31 // clean out cache if necessary
32 if ($AC['flush']) shell_exec('php ../maintenance/flush-definition-cache.php');
34 // initialize and load HTML Purifier
35 // use ?standalone to load the alterative standalone stub
36 if ($AC['standalone']) {
37 set_include_path(realpath('blanks') . PATH_SEPARATOR . get_include_path());
38 require_once '../library/HTMLPurifier.standalone.php';
39 } else {
40 require_once '../library/HTMLPurifier.auto.php';
42 require_once 'HTMLPurifier/Harness.php';
44 // setup special DefinitionCacheFactory decorator
45 $factory =& HTMLPurifier_DefinitionCacheFactory::instance();
46 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
48 // load tests
49 $test_files = array();
50 require 'test_files.php'; // populates $test_files array
51 sort($test_files); // for the SELECT
52 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
53 $test_file_lookup = array_flip($test_files);
55 // determine test file
56 if ($AC['file']) {
57 if (!isset($test_file_lookup[$AC['file']])) {
58 echo "Invalid file passed\n";
59 exit;
63 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
64 if ($AC['file']) {
66 $test = new TestSuite($AC['file']);
67 require_once $AC['file'];
68 $test->addTestClass(path2class($AC['file']));
70 } else {
72 $standalone = '';
73 if ($AC['standalone']) $standalone = ' (standalone)';
74 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
75 foreach ($test_files as $test_file) {
76 require_once $test_file;
77 $test->addTestClass(path2class($test_file));
82 if ($AC['xml']) {
83 if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
84 $reporter = new XmlReporter();
85 } elseif (SimpleReporter::inCli()) {
86 $reporter = new TextReporter();
87 } else {
88 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
91 if ($AC['dry']) $reporter->makeDry();
93 $test->run($reporter);