Have tests also check for test-settings in conf file, this allows for configuration...
[htmlpurifier/rdancer.git] / tests / index.php
blob98d9e23b87a340fcd2a65bc3b9d5078b1830baf7
1 <?php
3 // call one file using /?f=FileTest.php , see $test_files array for
4 // valid values
6 error_reporting(E_ALL);
7 define('HTMLPurifierTest', 1);
8 define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
10 // wishlist: automated calling of this file from multiple PHP versions so we
11 // don't have to constantly switch around
13 // default settings (protect against register_globals)
14 $GLOBALS['HTMLPurifierTest'] = array();
15 $GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
16 $GLOBALS['HTMLPurifierTest']['PH5P'] = version_compare(PHP_VERSION, "5", ">=") && class_exists('DOMDocument');
17 $simpletest_location = 'simpletest/'; // reasonable guess
19 // load SimpleTest
20 if (file_exists('../conf/test-settings.php')) include '../conf/test-settings.php';
21 if (file_exists('../test-settings.php')) include '../test-settings.php';
22 require_once $simpletest_location . 'unit_tester.php';
23 require_once $simpletest_location . 'reporter.php';
24 require_once $simpletest_location . 'mock_objects.php';
25 require_once 'HTMLPurifier/SimpleTest/Reporter.php';
27 // load Debugger
28 require_once 'Debugger.php';
30 // load convenience functions
31 require_once 'generate_mock_once.func.php';
32 require_once 'path2class.func.php';
33 require_once 'tally_errors.func.php'; // compat
35 // initialize PEAR (optional)
36 if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
37 // if PEAR is true, we assume that there's no need to
38 // add it to the path
39 set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR .
40 get_include_path());
43 // initialize and load HTML Purifier
44 // use ?standalone to load the alterative standalone stub
45 if (isset($_GET['standalone']) || (isset($argv[1]) && $argv[1] == 'standalone')) {
46 set_include_path(realpath('blanks') . PATH_SEPARATOR . get_include_path());
47 require_once '../library/HTMLPurifier.standalone.php';
48 } else {
49 require_once '../library/HTMLPurifier.auto.php';
51 require_once 'HTMLPurifier/Harness.php';
53 // setup special DefinitionCacheFactory decorator
54 $factory =& HTMLPurifier_DefinitionCacheFactory::instance();
55 $factory->addDecorator('Memory'); // since we deal with a lot of config objects
57 // load tests
58 $test_files = array();
59 require 'test_files.php'; // populates $test_files array
60 sort($test_files); // for the SELECT
61 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
62 $test_file_lookup = array_flip($test_files);
64 // determine test file
65 if (isset($_GET['f']) && isset($test_file_lookup[$_GET['f']])) {
66 $GLOBALS['HTMLPurifierTest']['File'] = $_GET['f'];
67 } elseif (isset($argv[1]) && isset($test_file_lookup[$argv[1]])) {
68 // command-line
69 $GLOBALS['HTMLPurifierTest']['File'] = $argv[1];
70 } else {
71 $GLOBALS['HTMLPurifierTest']['File'] = false;
74 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
75 if ($test_file = $GLOBALS['HTMLPurifierTest']['File']) {
77 $test = new GroupTest($test_file);
78 require_once $test_file;
79 $test->addTestClass(path2class($test_file));
81 } else {
83 $test = new GroupTest('All Tests');
84 foreach ($test_files as $test_file) {
85 require_once $test_file;
86 $test->addTestClass(path2class($test_file));
91 if (SimpleReporter::inCli()) $reporter = new TextReporter();
92 else $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8');
94 $test->run($reporter);