Merged 371:372 from branches/1.0/ to trunk/
[htmlpurifier.git] / tests / index.php
blobbeaf1831fdb26679f219ab30d07f11fe465e3932
1 <?php
3 error_reporting(E_ALL);
5 // wishlist: automated calling of this file from multiple PHP versions so we
6 // don't have to constantly switch around
8 // configuration
9 $GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
11 $simpletest_location = 'simpletest/';
12 if (file_exists('../test-settings.php')) include_once '../test-settings.php';
13 require_once $simpletest_location . 'unit_tester.php';
14 require_once $simpletest_location . 'reporter.php';
15 require_once $simpletest_location . 'mock_objects.php';
17 // configure PEAR if necessary
18 if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
19 set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR .
20 get_include_path());
23 // debugger
24 require_once 'Debugger.php';
26 // emulates inserting a dir called HTMLPurifier into your class dir
27 set_include_path('../library' . PATH_SEPARATOR . get_include_path());
29 // since Mocks can't be called from within test files, we need to do
30 // a little jumping through hoops to generate them
31 function generate_mock_once($name) {
32 $mock_name = $name . 'Mock';
33 if (class_exists($mock_name)) return false;
34 Mock::generate($name, $mock_name);
37 // this has to be defined before we do any includes of library files
38 require_once 'HTMLPurifier.php';
40 // define callable test files
41 $test_files = array();
42 $test_files[] = 'ConfigTest.php';
43 $test_files[] = 'ConfigDefTest.php';
44 $test_files[] = 'LexerTest.php';
45 $test_files[] = 'Lexer/DirectLexTest.php';
46 $test_files[] = 'TokenTest.php';
47 $test_files[] = 'ChildDefTest.php';
48 $test_files[] = 'GeneratorTest.php';
49 $test_files[] = 'EntityLookupTest.php';
50 $test_files[] = 'Strategy/RemoveForeignElementsTest.php';
51 $test_files[] = 'Strategy/MakeWellFormedTest.php';
52 $test_files[] = 'Strategy/FixNestingTest.php';
53 $test_files[] = 'Strategy/CompositeTest.php';
54 $test_files[] = 'Strategy/CoreTest.php';
55 $test_files[] = 'Strategy/ValidateAttributesTest.php';
56 $test_files[] = 'AttrDefTest.php';
57 $test_files[] = 'AttrDef/EnumTest.php';
58 $test_files[] = 'AttrDef/IDTest.php';
59 $test_files[] = 'AttrDef/ClassTest.php';
60 $test_files[] = 'AttrDef/TextTest.php';
61 $test_files[] = 'AttrDef/LangTest.php';
62 $test_files[] = 'AttrDef/PixelsTest.php';
63 $test_files[] = 'AttrDef/LengthTest.php';
64 $test_files[] = 'AttrDef/URITest.php';
65 $test_files[] = 'AttrDef/CSSTest.php';
66 $test_files[] = 'AttrDef/CompositeTest.php';
67 $test_files[] = 'AttrDef/ColorTest.php';
68 $test_files[] = 'AttrDef/IntegerTest.php';
69 $test_files[] = 'AttrDef/NumberTest.php';
70 $test_files[] = 'AttrDef/CSSLengthTest.php';
71 $test_files[] = 'AttrDef/PercentageTest.php';
72 $test_files[] = 'AttrDef/MultipleTest.php';
73 $test_files[] = 'AttrDef/TextDecorationTest.php';
74 $test_files[] = 'AttrDef/FontFamilyTest.php';
75 $test_files[] = 'AttrDef/HostTest.php';
76 $test_files[] = 'AttrDef/IPv4Test.php';
77 $test_files[] = 'AttrDef/IPv6Test.php';
78 $test_files[] = 'AttrDef/FontTest.php';
79 $test_files[] = 'AttrDef/BorderTest.php';
80 $test_files[] = 'AttrDef/ListStyleTest.php';
81 $test_files[] = 'IDAccumulatorTest.php';
82 $test_files[] = 'TagTransformTest.php';
83 $test_files[] = 'AttrTransform/LangTest.php';
84 $test_files[] = 'AttrTransform/TextAlignTest.php';
85 $test_files[] = 'AttrTransform/BdoDirTest.php';
86 $test_files[] = 'AttrTransform/ImgRequiredTest.php';
87 $test_files[] = 'URISchemeRegistryTest.php';
88 $test_files[] = 'URISchemeTest.php';
89 $test_files[] = 'EncoderTest.php';
90 $test_files[] = 'EntityParserTest.php';
91 $test_files[] = 'Test.php';
93 if (version_compare(PHP_VERSION, '5', '>=')) {
94 $test_files[] = 'TokenFactoryTest.php';
97 $test_file_lookup = array_flip($test_files);
99 function htmlpurifier_path2class($path) {
100 $temp = $path;
101 $temp = str_replace('./', '', $temp); // remove leading './'
102 $temp = str_replace('.\\', '', $temp); // remove leading '.\'
103 $temp = str_replace('\\', '_', $temp); // normalize \ to _
104 $temp = str_replace('/', '_', $temp); // normalize / to _
105 while(strpos($temp, '__') !== false) $temp = str_replace('__', '_', $temp);
106 $temp = str_replace('.php', '', $temp);
107 return $temp;
110 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
112 if (isset($_GET['file']) && isset($test_file_lookup[$_GET['file']])) {
114 // execute only one test
115 $test_file = $_GET['file'];
117 $test = new GroupTest('HTMLPurifier - ' . $test_file);
118 $path = 'HTMLPurifier/' . $test_file;
119 require_once $path;
120 $test->addTestClass(htmlpurifier_path2class($path));
122 } else {
124 $test = new GroupTest('HTMLPurifier');
126 foreach ($test_files as $test_file) {
127 $path = 'HTMLPurifier/' . $test_file;
128 require_once $path;
129 $test->addTestClass(htmlpurifier_path2class($path));
134 if (SimpleReporter::inCli()) $reporter = new TextReporter();
135 else $reporter = new HTMLReporter('UTF-8');
137 $test->run($reporter);