[3.1.0] Fixed bug with fallback languages in LanguageFactory
[htmlpurifier.git] / tests / multitest.php
blob07a278a4dd6f3c5aea8e0ad12058a6f211beb9a7
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 $php = 'php'; // for safety
29 require_once 'common.php';
31 if (!SimpleReporter::inCli()) {
32 echo 'Multitest only available from command line';
33 exit;
36 $AC = array(); // parameters
37 $AC['exclude-normal'] = false;
38 $AC['exclude-standalone'] = false;
39 $AC['file'] = '';
40 $AC['xml'] = false;
41 $AC['quiet'] = false;
42 $AC['php'] = $php;
43 $AC['disable-phpt'] = false;
44 $AC['only-phpt'] = false;
45 $aliases = array(
46 'f' => 'file',
47 'q' => 'quiet',
49 htmlpurifier_parse_args($AC, $aliases);
51 if ($AC['xml']) {
52 $reporter = new XmlReporter();
53 } else {
54 $reporter = new TextReporter();
57 // Regenerate any necessary files
58 htmlpurifier_flush($AC['php'], $reporter);
60 $file = '';
62 $test_files = array();
63 require 'test_files.php';
64 if ($AC['file']) {
65 $test_files_lookup = array_flip($test_files);
66 if (isset($test_files_lookup[$AC['file']])) {
67 $file = '--file=' . $AC['file'];
68 } else {
69 throw new Exception("Invalid file passed");
72 // This allows us to get out of having to do dry runs.
73 $size = count($test_files);
75 // Setup the test
76 $test = new TestSuite('HTML Purifier Multiple Versions Test');
77 foreach ($versions_to_test as $version) {
78 $flush = '';
79 if (is_array($version)) {
80 $version = $version[0];
81 $flush = '--flush';
83 if (!$AC['only-phpt']) {
84 if (!$AC['exclude-normal']) {
85 $test->add(
86 new CliTestCase(
87 "$phpv $version index.php --xml $flush --disable-phpt $file",
88 $AC['quiet'], $size
92 if (!$AC['exclude-standalone']) {
93 $test->add(
94 new CliTestCase(
95 "$phpv $version index.php --xml $flush --standalone --disable-phpt $file",
96 $AC['quiet'], $size
101 if (!$AC['disable-phpt']) { // naming is not consistent
102 $test->add(
103 new CliTestCase(
104 $AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
105 $AC['quiet'], $size
111 // This is the HTML Purifier website's test XML file. We could
112 // add more websites, i.e. more configurations to test.
113 // $test->add(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1'));
115 $test->run($reporter);