[3.0.0] Upgraded test scripts and other goodies. Also removed some PHP4 cruft.
[htmlpurifier/darkodev.git] / tests / index.php
blob50cf7985cd810833f8dbd61052d32baf45bac8d3
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 $aliases = array(
26 'f' => 'file',
28 htmlpurifier_parse_args($AC, $aliases);
30 // clean out cache if necessary
31 if ($AC['flush']) shell_exec('php ../maintenance/flush-definition-cache.php');
33 // initialize and load HTML Purifier
34 // use ?standalone to load the alterative standalone stub
35 if ($AC['standalone']) {
36 set_include_path(realpath('blanks') . PATH_SEPARATOR . get_include_path());
37 require_once '../library/HTMLPurifier.standalone.php';
38 } else {
39 require_once '../library/HTMLPurifier.auto.php';
41 require_once 'HTMLPurifier/Harness.php';
43 // setup special DefinitionCacheFactory decorator
44 $factory =& HTMLPurifier_DefinitionCacheFactory::instance();
45 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
47 // load tests
48 $test_files = array();
49 require 'test_files.php'; // populates $test_files array
50 sort($test_files); // for the SELECT
51 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
52 $test_file_lookup = array_flip($test_files);
54 // determine test file
55 if ($AC['file']) {
56 if (!isset($test_file_lookup[$AC['file']])) {
57 echo "Invalid file passed\n";
58 exit;
62 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
63 if ($AC['file']) {
65 $test = new TestSuite($AC['file']);
66 require_once $AC['file'];
67 $test->addTestClass(path2class($AC['file']));
69 } else {
71 $standalone = '';
72 if ($AC['standalone']) $standalone = ' (standalone)';
73 $test = new TestSuite('All HTML Purifier tests on PHP ' . PHP_VERSION . $standalone);
74 foreach ($test_files as $test_file) {
75 require_once $test_file;
76 $test->addTestClass(path2class($test_file));
81 if ($AC['xml']) {
82 if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8');
83 $reporter = new XmlReporter();
84 } elseif (SimpleReporter::inCli()) {
85 $reporter = new TextReporter();
86 } else {
87 $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
90 $test->run($reporter);