[3.1.0] When flush fails, fail SimpleTest
[htmlpurifier.git] / tests / multitest.php
blob7a14b8210595465a51c927975cb26b64598775e8
1 <?php
3 /** @file
4 * Multiple PHP Versions test
5 *
6 * This file tests HTML Purifier in all versions of PHP. Arguments
7 * are specified like --arg=opt, allowed arguments are:
8 * - exclude-normal, excludes normal tests
9 * - exclude-standalone, excludes standalone tests
10 * - file (f), specifies a single file to test for all versions
11 * - xml, if specified output is XML
12 * - quiet (q), if specified no informative messages are enabled (please use
13 * this if you're outputting XML)
15 * @note
16 * It requires a script called phpv that takes an extra argument (the
17 * version number of PHP) before all other arguments. Contact me if you'd
18 * like to set up a similar script. The name of the script can be
19 * edited with $phpv
21 * @note
22 * Also, configuration must be set up with a variable called
23 * $versions_to_test specifying version numbers to pass to $phpv
26 define('HTMLPurifierTest', 1);
27 require_once 'common.php';
29 if (!SimpleReporter::inCli()) {
30 echo 'Multitest only available from command line';
31 exit;
34 $AC = array(); // parameters
35 $AC['exclude-normal'] = false;
36 $AC['exclude-standalone'] = false;
37 $AC['file'] = '';
38 $AC['xml'] = false;
39 $AC['quiet'] = false;
40 $AC['php'] = 'php';
41 $AC['disable-phpt'] = false;
42 $AC['only-phpt'] = false;
43 $aliases = array(
44 'f' => 'file',
45 'q' => 'quiet',
47 htmlpurifier_parse_args($AC, $aliases);
49 if ($AC['xml']) {
50 $reporter = new XmlReporter();
51 } else {
52 $reporter = new TextReporter();
55 // Regenerate any necessary files
56 htmlpurifier_flush($AC['php'], $reporter);
58 $file = '';
60 $test_files = array();
61 require 'test_files.php';
62 if ($AC['file']) {
63 $test_files_lookup = array_flip($test_files);
64 if (isset($test_files_lookup[$AC['file']])) {
65 $file = '--file=' . $AC['file'];
66 } else {
67 throw new Exception("Invalid file passed");
70 // This allows us to get out of having to do dry runs.
71 $size = count($test_files);
73 // Setup the test
74 $test = new TestSuite('HTML Purifier Multiple Versions Test');
75 foreach ($versions_to_test as $version) {
76 $flush = '';
77 if (is_array($version)) {
78 $version = $version[0];
79 $flush = '--flush';
81 if (!$AC['only-phpt']) {
82 if (!$AC['exclude-normal']) {
83 $test->addTestCase(
84 new CliTestCase(
85 "$phpv $version index.php --xml $flush --disable-phpt $file",
86 $AC['quiet'], $size
90 if (!$AC['exclude-standalone']) {
91 $test->addTestCase(
92 new CliTestCase(
93 "$phpv $version index.php --xml $flush --standalone --disable-phpt $file",
94 $AC['quiet'], $size
99 if (!$AC['disable-phpt']) { // naming is not consistent
100 $test->addTestCase(
101 new CliTestCase(
102 $AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
103 $AC['quiet'], $size
109 // This is the HTML Purifier website's test XML file. We could
110 // add more websites, i.e. more configurations to test.
111 $test->addTestCase(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1'));
113 $test->run($reporter);
115 shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');