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
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
.
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';
91 if (version_compare(PHP_VERSION
, '5', '>=')) {
92 $test_files[] = 'TokenFactoryTest.php';
95 $test_file_lookup = array_flip($test_files);
97 function htmlpurifier_path2class($path) {
99 $temp = str_replace('./', '', $temp); // remove leading './'
100 $temp = str_replace('.\\', '', $temp); // remove leading '.\'
101 $temp = str_replace('\\', '_', $temp); // normalize \ to _
102 $temp = str_replace('/', '_', $temp); // normalize / to _
103 while(strpos($temp, '__') !== false) $temp = str_replace('__', '_', $temp);
104 $temp = str_replace('.php', '', $temp);
108 // we can't use addTestFile because SimpleTest chokes on E_STRICT warnings
110 if (isset($_GET['file']) && isset($test_file_lookup[$_GET['file']])) {
112 // execute only one test
113 $test_file = $_GET['file'];
115 $test = new GroupTest('HTMLPurifier - ' . $test_file);
116 $path = 'HTMLPurifier/' . $test_file;
118 $test->addTestClass(htmlpurifier_path2class($path));
122 $test = new GroupTest('HTMLPurifier');
124 foreach ($test_files as $test_file) {
125 $path = 'HTMLPurifier/' . $test_file;
127 $test->addTestClass(htmlpurifier_path2class($path));
132 if (SimpleReporter
::inCli()) $reporter = new TextReporter();
133 else $reporter = new HTMLReporter('UTF-8');
135 $test->run($reporter);