Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 334ffac

Browse files
author
Edward Z. Yang
committed
Various improvements to test script command line options, i.e. --type
The following changes were made: * Create --type parameter which accepts 'htmlpurifier', 'phpt', 'vtest', etc. in order to execute only that class of tests. This supercedes --only-phpt. * Create --quick parameter for multitest.php, run only the tips of each release series. * Create --distro parameter for multitest.php, supercedes --exclude-normal and --exclude-standalone. Also, a grep for htmlt tests was added, although add_tests() doesn't do anything with it yet. Signed-off-by: Edward Z. Yang <[email protected]>
1 parent a227cb4 commit 334ffac

4 files changed

Lines changed: 135 additions & 76 deletions

File tree

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
2222
the strategy to be used, standalone, on untrusted input.
2323
! %Core.AggressivelyFixLt is on by default. This causes more sensible
2424
processing of left angled brackets in smileys and other whatnot.
25+
! Test scripts now have a 'type' parameter, which lets you say 'htmlpurifier',
26+
'phpt', 'vtest', etc. in order to only execute those tests. This supercedes
27+
the --only-phpt parameter, although for backwards-compatibility the flag
28+
will still work.
2529
- Fix two bugs in %URI.MakeAbsolute; one involving empty paths in base URLs,
2630
the other involving an undefined $is_folder error.
2731
- Throw error when %Core.Encoding is set to a spurious value. Previously,
@@ -33,6 +37,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
3337
index to reprocess tokens.
3438
. StringHashParser now allows for multiline sections with "empty" content;
3539
previously the section would remain undefined.
40+
. Added --quick option to multitest.php, which tests only the most recent
41+
release for each series.
42+
. Added --distro option to multitest.php, which accepts either 'normal' or
43+
'standalone'. This supercedes --exclude-normal and --exclude-standalone
3644

3745
3.1.1, released 2008-06-19
3846
# %URI.Munge now, by default, does not munge resources (for example, <img src="">)

tests/index.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* - file (f), a single file to test
1212
* - xml, whether or not to output XML
1313
* - dry, whether or not to do a dry run
14+
* - type, the type of tests to run, can be 'htmlpurifier', 'configdoc',
15+
* 'fstools', 'htmlt', 'vtest' or 'phpt'
1416
*
1517
* If you're interested in running the test-cases, mosey over to
1618
* ../test-settings.sample.php, copy the file to test-settings.php and follow
@@ -38,10 +40,9 @@
3840
$AC['dry'] = false;
3941
$AC['php'] = $php;
4042

41-
// Convenience parameters for running quicker tests; ideally all tests
42-
// should be performed.
43+
$AC['type'] = '';
4344
$AC['disable-phpt'] = false;
44-
$AC['only-phpt'] = false;
45+
$AC['only-phpt'] = false; // alias for --type=phpt
4546

4647
$aliases = array(
4748
'f' => 'file',
@@ -52,18 +53,18 @@
5253
htmlpurifier_parse_args($AC, $aliases);
5354

5455
// Disable PHPT tests if they're not enabled
55-
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) $AC['disable-phpt'] = true;
56+
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
57+
$AC['disable-phpt'] = true;
58+
} elseif (!$AC['type'] && $AC['only-phpt']) {
59+
// backwards-compat
60+
$AC['type'] = 'phpt';
61+
}
5662

5763
if (!SimpleReporter::inCli()) {
5864
// Undo any dangerous parameters
5965
$AC['php'] = $php;
6066
}
6167

62-
if ($AC['disable-phpt'] && $AC['only-phpt']) {
63-
echo "Cannot disable and allow only PHPT tests!\n";
64-
exit(1);
65-
}
66-
6768
// Shell-script code is executed
6869

6970
if ($AC['xml']) {
@@ -102,14 +103,7 @@
102103
}
103104

104105
// load tests
105-
106-
$test_files = array();
107-
$test_dirs = array();
108-
$test_dirs_exclude = array();
109-
$vtest_dirs = array();
110-
$phpt_dirs = array();
111-
112-
require 'test_files.php'; // populates $test_files array
106+
require 'test_files.php';
113107

114108
$FS = new FSTools();
115109

@@ -139,6 +133,14 @@
139133
}
140134
}
141135

136+
// handle htmlt dirs
137+
foreach ($htmlt_dirs as $dir) {
138+
$htmlt_files = $FS->globr($dir, '*.htmlt');
139+
foreach ($htmlt_files as $file) {
140+
$test_files[] = str_replace('\\', '/', $file);
141+
}
142+
}
143+
142144
array_unique($test_files);
143145
sort($test_files); // for the SELECT
144146
$GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter

tests/multitest.php

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*
66
* This file tests HTML Purifier in all versions of PHP. Arguments
77
* 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
128
* - quiet (q), if specified no informative messages are enabled (please use
139
* 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
1416
*
1517
* @note
1618
* It requires a script called phpv that takes an extra argument (the
@@ -24,6 +26,7 @@
2426
*/
2527

2628
define('HTMLPurifierTest', 1);
29+
chdir(dirname(__FILE__));
2730
$php = 'php'; // for safety
2831

2932
require_once 'common.php';
@@ -34,74 +37,111 @@
3437
}
3538

3639
$AC = array(); // parameters
37-
$AC['exclude-normal'] = false;
38-
$AC['exclude-standalone'] = false;
3940
$AC['file'] = '';
4041
$AC['xml'] = false;
4142
$AC['quiet'] = false;
4243
$AC['php'] = $php;
4344
$AC['disable-phpt'] = false;
44-
$AC['only-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
4554
$aliases = array(
4655
'f' => 'file',
4756
'q' => 'quiet',
4857
);
4958
htmlpurifier_parse_args($AC, $aliases);
5059

60+
// Backwards compat extra parsing
61+
if ($AC['only-phpt']) {
62+
$AC['type'] = 'phpt';
63+
}
64+
if ($AC['exclude-normal']) $AC['distro'] = 'standalone';
65+
elseif ($AC['exclude-standalone']) $AC['distro'] = 'normal';
66+
elseif ($AC['standalone']) $AC['distro'] = 'standalone';
67+
5168
if ($AC['xml']) {
5269
$reporter = new XmlReporter();
5370
} else {
5471
$reporter = new TextReporter();
5572
}
5673

5774
// Regenerate any necessary files
58-
htmlpurifier_flush($AC['php'], $reporter);
59-
60-
$file = '';
75+
if (!$AC['disable-flush']) htmlpurifier_flush($AC['php'], $reporter);
6176

62-
$test_files = array();
77+
$file_arg = '';
6378
require 'test_files.php';
6479
if ($AC['file']) {
6580
$test_files_lookup = array_flip($test_files);
6681
if (isset($test_files_lookup[$AC['file']])) {
67-
$file = '--file=' . $AC['file'];
82+
$file_arg = '--file=' . $AC['file'];
6883
} else {
6984
throw new Exception("Invalid file passed");
7085
}
7186
}
7287
// This allows us to get out of having to do dry runs.
7388
$size = count($test_files);
7489

90+
$type_arg = '';
91+
if ($AC['type']) $type_arg = '--type=' . $AC['type'];
92+
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;
100+
}
101+
if (version_compare($version, $seriesArray[$series], '>')) {
102+
$seriesArray[$series] = $version;
103+
}
104+
}
105+
$versions_to_test = array_values($seriesArray);
106+
}
107+
75108
// Setup the test
76109
$test = new TestSuite('HTML Purifier Multiple Versions Test');
77110
foreach ($versions_to_test as $version) {
78-
$flush = '';
111+
// Support for arbitrarily forcing flushes by wrapping the suspect
112+
// version name in an array()
113+
$flush_arg = '';
79114
if (is_array($version)) {
80115
$version = $version[0];
81-
$flush = '--flush';
116+
$flush_arg = '--flush';
82117
}
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
89-
)
90-
);
91-
}
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
97-
)
98-
);
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
128+
)
129+
);
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
136+
)
137+
);
138+
if ($break) break;
99139
}
100140
}
101-
if (!$AC['disable-phpt']) { // naming is not consistent
141+
if (!$AC['disable-phpt'] && (!$AC['type'] || $AC['type'] == 'phpt')) {
102142
$test->add(
103143
new CliTestCase(
104-
$AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
144+
$AC['php'] . " index.php --xml --php \"$phpv $version\" --type=phpt",
105145
$AC['quiet'], $size
106146
)
107147
);

tests/test_files.php

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@
22

33
if (!defined('HTMLPurifierTest')) exit;
44

5-
// define callable test files (sorted alphabetically)
5+
// These arrays are defined by this file and can be relied upon.
6+
$test_files = array();
7+
$test_dirs = array();
8+
$test_dirs_exclude = array();
9+
$vtest_dirs = array();
10+
$htmlt_dirs = array();
11+
$phpt_dirs = array();
612

7-
if (!$AC['only-phpt']) {
13+
$break = true;
14+
switch ($AC['type']) {
15+
case '':
16+
$break = false;
17+
case 'htmlpurifier':
18+
$test_dirs[] = 'HTMLPurifier';
19+
$test_files[] = 'HTMLPurifierTest.php';
20+
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
21+
if ($csstidy_location) {
22+
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
23+
}
24+
if ($break) break;
25+
case 'configdoc':
26+
if (version_compare(PHP_VERSION, '5.2', '>=')) {
27+
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
28+
}
29+
if ($break) break;
30+
case 'fstools':
31+
$test_dirs[] = 'FSTools';
32+
case 'htmlt':
33+
$htmlt_dirs[] = 'HTMLPurifier/HTMLT';
34+
if ($break) break;
35+
case 'vtest':
36+
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
37+
if ($break) break;
838

9-
// HTML Purifier main library
10-
$test_dirs[] = 'HTMLPurifier';
11-
$test_files[] = 'HTMLPurifierTest.php';
12-
13-
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
14-
if ($csstidy_location) {
15-
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
16-
}
17-
18-
// ConfigSchema Validator tests
19-
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
20-
21-
// ConfigDoc auxiliary library
22-
if (version_compare(PHP_VERSION, '5.2', '>=')) {
23-
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
24-
}
25-
26-
// FSTools auxiliary library
27-
$test_dirs[] = 'FSTools';
28-
29-
}
30-
31-
// PHPT tests
32-
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
33-
$phpt_dirs[] = 'HTMLPurifier/PHPT';
39+
case 'phpt':
40+
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
41+
$phpt_dirs[] = 'HTMLPurifier/PHPT';
42+
}
3443
}

0 commit comments

Comments
 (0)