[3.1.0] Implement a few phpt, fix some autoload bugs
[htmlpurifier/rdancer.git] / tests / index.php
blob0591d939a6166789bdb89249f309dad1cd3a9226
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
13 * - dry, whether or not to do a dry run
16 define('HTMLPurifierTest', 1);
17 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
18 chdir(dirname(__FILE__));
20 require_once 'common.php';
22 $AC = array(); // parameters
23 $AC['flush'] = false;
24 $AC['standalone'] = false;
25 $AC['file'] = '';
26 $AC['xml'] = false;
27 $AC['dry'] = false;
28 $AC['php'] = 'php';
30 // Convenience parameters for running quicker tests; ideally all tests
31 // should be performed.
32 $AC['disable-phpt'] = false;
33 $AC['only-phpt'] = false;
35 $aliases = array(
36 'f' => 'file',
38 htmlpurifier_parse_args($AC, $aliases);
40 if (!SimpleReporter::inCli()) {
41 // Undo any dangerous parameters
42 $AC['php'] = 'php';
45 if ($AC['disable-phpt'] && $AC['only-phpt']) {
46 echo "Cannot disable and allow only PHPT tests!\n";
47 exit(1);
50 if (!$AC['disable-phpt']) {
51 $phpt = PHPT_Registry::getInstance();
52 $phpt->php = $AC['php'];
55 // clean out cache if necessary
56 if ($AC['flush']) shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');
58 // initialize and load alternative classes
59 require_once '../extras/HTMLPurifierExtras.auto.php';
62 // initialize and load HTML Purifier
63 // use ?standalone to load the alterative standalone stub
64 if ($AC['standalone']) {
65 set_include_path(realpath('../library/standalone') . PATH_SEPARATOR . realpath('blanks') . PATH_SEPARATOR . get_include_path());
66 require_once '../library/HTMLPurifier.standalone.php';
67 } else {
68 set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path() );
69 require_once 'HTMLPurifier.auto.php';
70 require_once 'HTMLPurifier.includes.php';
72 require_once 'HTMLPurifier/Harness.php';
74 // setup special DefinitionCacheFactory decorator
75 $factory =& HTMLPurifier_DefinitionCacheFactory::instance();
76 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
78 // load tests
79 $test_files = array();
80 require 'test_files.php'; // populates $test_files array
81 sort($test_files); // for the SELECT
82 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
83 $test_file_lookup = array_flip($test_files);
85 // determine test file
86 if ($AC['file']) {
87 if (!isset($test_file_lookup[$AC['file']])) {
88 echo "Invalid file passed\n";
89 exit;
93 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
94 if ($AC['file']) {
96 $test = new TestSuite($AC['file']);
97 htmlpurifier_add_test($test, $AC['file']);
99 } else {
101 $standalone = '';
102 if ($AC['standalone']) $standalone = ' (standalone)';
103 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
104 foreach ($test_files as $test_file) {
105 htmlpurifier_add_test($test, $test_file);
110 if ($AC['xml']) {
111 if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
112 $reporter = new XmlReporter();
113 } elseif (SimpleReporter::inCli()) {
114 $reporter = new TextReporter();
115 } else {
116 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
119 if ($AC['dry']) $reporter->makeDry();
121 $test->run($reporter);