Explicitly initialize anonModule to null.
[htmlpurifier.git] / tests / multitest.php
blob518d4b625aff732f71bcd078fc585a5fba3ac7df
1 <?php
3 /** @file
4 * Multiple PHP Versions test
6 * This file tests HTML Purifier in all versions of PHP. Arguments
7 * are specified like --arg=opt, allowed arguments are:
8 * - quiet (q), if specified no informative messages are enabled (please use
9 * this if you're outputting XML)
10 * - distro, allowed values 'normal' or 'standalone', by default all
11 * distributions are tested. "--standalone" is a shortcut for
12 * "--distro=standalone".
13 * - quick, run only the most recent versions of each release series
14 * - disable-flush, by default flush is run, this disables it
15 * - file (f), xml, type: these correspond to the parameters in index.php
17 * @note
18 * It requires a script called phpv that takes an extra argument (the
19 * version number of PHP) before all other arguments. Contact me if you'd
20 * like to set up a similar script. The name of the script can be
21 * edited with $phpv
23 * @note
24 * Also, configuration must be set up with a variable called
25 * $versions_to_test specifying version numbers to pass to $phpv
28 define('HTMLPurifierTest', 1);
29 chdir(dirname(__FILE__));
30 $php = 'php'; // for safety
32 require_once 'common.php';
34 if (!SimpleReporter::inCli()) {
35 echo 'Multitest only available from command line';
36 exit;
39 $AC = array(); // parameters
40 $AC['file'] = '';
41 $AC['xml'] = false;
42 $AC['quiet'] = false;
43 $AC['php'] = $php;
44 $AC['disable-phpt'] = false;
45 $AC['disable-flush'] = false;
46 $AC['type'] = '';
47 $AC['distro'] = ''; // valid values are normal/standalone
48 $AC['quick'] = false; // run the latest version on each release series
49 $AC['standalone'] = false; // convenience for --distro=standalone
50 // Legacy parameters
51 $AC['only-phpt'] = false; // --type=phpt
52 $AC['exclude-normal'] = false; // --distro=standalone
53 $AC['exclude-standalone'] = false; // --distro=normal
54 $aliases = array(
55 'f' => 'file',
56 'q' => 'quiet',
58 htmlpurifier_parse_args($AC, $aliases);
60 // Backwards compat extra parsing
61 if ($AC['only-phpt']) {
62 $AC['type'] = 'phpt';
64 if ($AC['exclude-normal']) $AC['distro'] = 'standalone';
65 elseif ($AC['exclude-standalone']) $AC['distro'] = 'normal';
66 elseif ($AC['standalone']) $AC['distro'] = 'standalone';
68 if ($AC['xml']) {
69 $reporter = new XmlReporter();
70 } else {
71 $reporter = new TextReporter();
74 // Regenerate any necessary files
75 if (!$AC['disable-flush']) htmlpurifier_flush($AC['php'], $reporter);
77 $file_arg = '';
78 require 'test_files.php';
79 if ($AC['file']) {
80 $test_files_lookup = array_flip($test_files);
81 if (isset($test_files_lookup[$AC['file']])) {
82 $file_arg = '--file=' . $AC['file'];
83 } else {
84 throw new Exception("Invalid file passed");
87 // This allows us to get out of having to do dry runs.
88 $size = count($test_files);
90 $type_arg = '';
91 if ($AC['type']) $type_arg = '--type=' . $AC['type'];
93 if ($AC['quick']) {
94 $seriesArray = array();
95 foreach ($versions_to_test as $version) {
96 $series = substr($version, 0, strpos($version, '.', strpos($version, '.') + 1));
97 if (!isset($seriesArray[$series])) {
98 $seriesArray[$series] = $version;
99 continue;
101 if (version_compare($version, $seriesArray[$series], '>')) {
102 $seriesArray[$series] = $version;
105 $versions_to_test = array_values($seriesArray);
108 // Setup the test
109 $test = new TestSuite('HTML Purifier Multiple Versions Test');
110 foreach ($versions_to_test as $version) {
111 // Support for arbitrarily forcing flushes by wrapping the suspect
112 // version name in an array()
113 $flush_arg = '';
114 if (is_array($version)) {
115 $version = $version[0];
116 $flush_arg = '--flush';
118 if ($AC['type'] !== 'phpt') {
119 $break = true;
120 switch ($AC['distro']) {
121 case '':
122 $break = false;
123 case 'normal':
124 $test->add(
125 new CliTestCase(
126 "$phpv $version index.php --xml $flush_arg $type_arg --disable-phpt $file_arg",
127 $AC['quiet'], $size
130 if ($break) break;
131 case 'standalone':
132 $test->add(
133 new CliTestCase(
134 "$phpv $version index.php --xml $flush_arg $type_arg --standalone --disable-phpt $file_arg",
135 $AC['quiet'], $size
138 if ($break) break;
141 if (!$AC['disable-phpt'] && (!$AC['type'] || $AC['type'] == 'phpt')) {
142 $test->add(
143 new CliTestCase(
144 $AC['php'] . " index.php --xml --php \"$phpv $version\" --type=phpt",
145 $AC['quiet'], $size
151 // This is the HTML Purifier website's test XML file. We could
152 // add more websites, i.e. more configurations to test.
153 // $test->add(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1'));
155 $test->run($reporter);
157 // vim: et sw=4 sts=4