Release 2.0.1, merged in 1181 to HEAD.
[htmlpurifier.git] / tests / index.php
blobaad6a94c482b8c4c057df5703a68f604e34d4bcc
1 <?php
3 // call one file using /?f=FileTest.php , see $test_files array for
4 // valid values
6 error_reporting(E_ALL | E_STRICT);
7 define('HTMLPurifierTest', 1);
9 // wishlist: automated calling of this file from multiple PHP versions so we
10 // don't have to constantly switch around
12 // default settings (protect against register_globals)
13 $GLOBALS['HTMLPurifierTest'] = array();
14 $GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
15 $simpletest_location = 'simpletest/'; // reasonable guess
17 // load SimpleTest
18 @include '../test-settings.php'; // don't mind if it isn't there
19 require_once $simpletest_location . 'unit_tester.php';
20 require_once $simpletest_location . 'reporter.php';
21 require_once $simpletest_location . 'mock_objects.php';
22 require_once 'HTMLPurifier/SimpleTest/Reporter.php';
24 // load Debugger
25 require_once 'Debugger.php';
27 // load convenience functions
28 require_once 'generate_mock_once.func.php';
29 require_once 'path2class.func.php';
30 require_once 'tally_errors.func.php'; // compat
32 // initialize PEAR (optional)
33 if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
34 // if PEAR is true, we assume that there's no need to
35 // add it to the path
36 set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR .
37 get_include_path());
40 // initialize and load HTML Purifier
41 require_once '../library/HTMLPurifier.auto.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 (isset($_GET['f']) && isset($test_file_lookup[$_GET['f']])) {
56 $GLOBALS['HTMLPurifierTest']['File'] = $_GET['f'];
57 } elseif (isset($argv[1]) && isset($test_file_lookup[$argv[1]])) {
58 // command-line
59 $GLOBALS['HTMLPurifierTest']['File'] = $argv[1];
60 } else {
61 $GLOBALS['HTMLPurifierTest']['File'] = false;
64 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
65 if ($test_file = $GLOBALS['HTMLPurifierTest']['File']) {
67 $test = new GroupTest($test_file);
68 require_once $test_file;
69 $test->addTestClass(path2class($test_file));
71 } else {
73 $test = new GroupTest('All Tests');
75 foreach ($test_files as $test_file) {
76 require_once $test_file;
77 $test->addTestClass(path2class($test_file));
82 if (SimpleReporter::inCli()) $reporter = new TextReporter();
83 else $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8');
85 $test->run($reporter);