mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-08 06:48:42 +00:00
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 <edwardzyang@thewritingpot.com>
This commit is contained in:
parent
a227cb483a
commit
334ffac5b4
8
NEWS
8
NEWS
@ -22,6 +22,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||
the strategy to be used, standalone, on untrusted input.
|
||||
! %Core.AggressivelyFixLt is on by default. This causes more sensible
|
||||
processing of left angled brackets in smileys and other whatnot.
|
||||
! Test scripts now have a 'type' parameter, which lets you say 'htmlpurifier',
|
||||
'phpt', 'vtest', etc. in order to only execute those tests. This supercedes
|
||||
the --only-phpt parameter, although for backwards-compatibility the flag
|
||||
will still work.
|
||||
- Fix two bugs in %URI.MakeAbsolute; one involving empty paths in base URLs,
|
||||
the other involving an undefined $is_folder error.
|
||||
- Throw error when %Core.Encoding is set to a spurious value. Previously,
|
||||
@ -33,6 +37,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||
index to reprocess tokens.
|
||||
. StringHashParser now allows for multiline sections with "empty" content;
|
||||
previously the section would remain undefined.
|
||||
. Added --quick option to multitest.php, which tests only the most recent
|
||||
release for each series.
|
||||
. Added --distro option to multitest.php, which accepts either 'normal' or
|
||||
'standalone'. This supercedes --exclude-normal and --exclude-standalone
|
||||
|
||||
3.1.1, released 2008-06-19
|
||||
# %URI.Munge now, by default, does not munge resources (for example, <img src="">)
|
||||
|
@ -11,6 +11,8 @@
|
||||
* - file (f), a single file to test
|
||||
* - xml, whether or not to output XML
|
||||
* - dry, whether or not to do a dry run
|
||||
* - type, the type of tests to run, can be 'htmlpurifier', 'configdoc',
|
||||
* 'fstools', 'htmlt', 'vtest' or 'phpt'
|
||||
*
|
||||
* If you're interested in running the test-cases, mosey over to
|
||||
* ../test-settings.sample.php, copy the file to test-settings.php and follow
|
||||
@ -38,10 +40,9 @@ $AC['xml'] = false;
|
||||
$AC['dry'] = false;
|
||||
$AC['php'] = $php;
|
||||
|
||||
// Convenience parameters for running quicker tests; ideally all tests
|
||||
// should be performed.
|
||||
$AC['type'] = '';
|
||||
$AC['disable-phpt'] = false;
|
||||
$AC['only-phpt'] = false;
|
||||
$AC['only-phpt'] = false; // alias for --type=phpt
|
||||
|
||||
$aliases = array(
|
||||
'f' => 'file',
|
||||
@ -52,18 +53,18 @@ $aliases = array(
|
||||
htmlpurifier_parse_args($AC, $aliases);
|
||||
|
||||
// Disable PHPT tests if they're not enabled
|
||||
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) $AC['disable-phpt'] = true;
|
||||
if (!$GLOBALS['HTMLPurifierTest']['PHPT']) {
|
||||
$AC['disable-phpt'] = true;
|
||||
} elseif (!$AC['type'] && $AC['only-phpt']) {
|
||||
// backwards-compat
|
||||
$AC['type'] = 'phpt';
|
||||
}
|
||||
|
||||
if (!SimpleReporter::inCli()) {
|
||||
// Undo any dangerous parameters
|
||||
$AC['php'] = $php;
|
||||
}
|
||||
|
||||
if ($AC['disable-phpt'] && $AC['only-phpt']) {
|
||||
echo "Cannot disable and allow only PHPT tests!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Shell-script code is executed
|
||||
|
||||
if ($AC['xml']) {
|
||||
@ -102,14 +103,7 @@ if (!$AC['disable-phpt']) {
|
||||
}
|
||||
|
||||
// load tests
|
||||
|
||||
$test_files = array();
|
||||
$test_dirs = array();
|
||||
$test_dirs_exclude = array();
|
||||
$vtest_dirs = array();
|
||||
$phpt_dirs = array();
|
||||
|
||||
require 'test_files.php'; // populates $test_files array
|
||||
require 'test_files.php';
|
||||
|
||||
$FS = new FSTools();
|
||||
|
||||
@ -139,6 +133,14 @@ foreach ($phpt_dirs as $dir) {
|
||||
}
|
||||
}
|
||||
|
||||
// handle htmlt dirs
|
||||
foreach ($htmlt_dirs as $dir) {
|
||||
$htmlt_files = $FS->globr($dir, '*.htmlt');
|
||||
foreach ($htmlt_files as $file) {
|
||||
$test_files[] = str_replace('\\', '/', $file);
|
||||
}
|
||||
}
|
||||
|
||||
array_unique($test_files);
|
||||
sort($test_files); // for the SELECT
|
||||
$GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
|
||||
|
@ -5,12 +5,14 @@
|
||||
*
|
||||
* This file tests HTML Purifier in all versions of PHP. Arguments
|
||||
* are specified like --arg=opt, allowed arguments are:
|
||||
* - exclude-normal, excludes normal tests
|
||||
* - exclude-standalone, excludes standalone tests
|
||||
* - file (f), specifies a single file to test for all versions
|
||||
* - xml, if specified output is XML
|
||||
* - quiet (q), if specified no informative messages are enabled (please use
|
||||
* this if you're outputting XML)
|
||||
* - distro, allowed values 'normal' or 'standalone', by default all
|
||||
* distributions are tested. "--standalone" is a shortcut for
|
||||
* "--distro=standalone".
|
||||
* - quick, run only the most recent versions of each release series
|
||||
* - disable-flush, by default flush is run, this disables it
|
||||
* - file (f), xml, type: these correspond to the parameters in index.php
|
||||
*
|
||||
* @note
|
||||
* It requires a script called phpv that takes an extra argument (the
|
||||
@ -24,6 +26,7 @@
|
||||
*/
|
||||
|
||||
define('HTMLPurifierTest', 1);
|
||||
chdir(dirname(__FILE__));
|
||||
$php = 'php'; // for safety
|
||||
|
||||
require_once 'common.php';
|
||||
@ -34,20 +37,34 @@ if (!SimpleReporter::inCli()) {
|
||||
}
|
||||
|
||||
$AC = array(); // parameters
|
||||
$AC['exclude-normal'] = false;
|
||||
$AC['exclude-standalone'] = false;
|
||||
$AC['file'] = '';
|
||||
$AC['xml'] = false;
|
||||
$AC['quiet'] = false;
|
||||
$AC['php'] = $php;
|
||||
$AC['disable-phpt'] = false;
|
||||
$AC['only-phpt'] = false;
|
||||
$AC['disable-flush'] = false;
|
||||
$AC['type'] = '';
|
||||
$AC['distro'] = ''; // valid values are normal/standalone
|
||||
$AC['quick'] = false; // run the latest version on each release series
|
||||
$AC['standalone'] = false; // convenience for --distro=standalone
|
||||
// Legacy parameters
|
||||
$AC['only-phpt'] = false; // --type=phpt
|
||||
$AC['exclude-normal'] = false; // --distro=standalone
|
||||
$AC['exclude-standalone'] = false; // --distro=normal
|
||||
$aliases = array(
|
||||
'f' => 'file',
|
||||
'q' => 'quiet',
|
||||
);
|
||||
htmlpurifier_parse_args($AC, $aliases);
|
||||
|
||||
// Backwards compat extra parsing
|
||||
if ($AC['only-phpt']) {
|
||||
$AC['type'] = 'phpt';
|
||||
}
|
||||
if ($AC['exclude-normal']) $AC['distro'] = 'standalone';
|
||||
elseif ($AC['exclude-standalone']) $AC['distro'] = 'normal';
|
||||
elseif ($AC['standalone']) $AC['distro'] = 'standalone';
|
||||
|
||||
if ($AC['xml']) {
|
||||
$reporter = new XmlReporter();
|
||||
} else {
|
||||
@ -55,16 +72,14 @@ if ($AC['xml']) {
|
||||
}
|
||||
|
||||
// Regenerate any necessary files
|
||||
htmlpurifier_flush($AC['php'], $reporter);
|
||||
if (!$AC['disable-flush']) htmlpurifier_flush($AC['php'], $reporter);
|
||||
|
||||
$file = '';
|
||||
|
||||
$test_files = array();
|
||||
$file_arg = '';
|
||||
require 'test_files.php';
|
||||
if ($AC['file']) {
|
||||
$test_files_lookup = array_flip($test_files);
|
||||
if (isset($test_files_lookup[$AC['file']])) {
|
||||
$file = '--file=' . $AC['file'];
|
||||
$file_arg = '--file=' . $AC['file'];
|
||||
} else {
|
||||
throw new Exception("Invalid file passed");
|
||||
}
|
||||
@ -72,36 +87,61 @@ if ($AC['file']) {
|
||||
// This allows us to get out of having to do dry runs.
|
||||
$size = count($test_files);
|
||||
|
||||
$type_arg = '';
|
||||
if ($AC['type']) $type_arg = '--type=' . $AC['type'];
|
||||
|
||||
if ($AC['quick']) {
|
||||
$seriesArray = array();
|
||||
foreach ($versions_to_test as $version) {
|
||||
$series = substr($version, 0, strpos($version, '.', strpos($version, '.') + 1));
|
||||
if (!isset($seriesArray[$series])) {
|
||||
$seriesArray[$series] = $version;
|
||||
continue;
|
||||
}
|
||||
if (version_compare($version, $seriesArray[$series], '>')) {
|
||||
$seriesArray[$series] = $version;
|
||||
}
|
||||
}
|
||||
$versions_to_test = array_values($seriesArray);
|
||||
}
|
||||
|
||||
// Setup the test
|
||||
$test = new TestSuite('HTML Purifier Multiple Versions Test');
|
||||
foreach ($versions_to_test as $version) {
|
||||
$flush = '';
|
||||
// Support for arbitrarily forcing flushes by wrapping the suspect
|
||||
// version name in an array()
|
||||
$flush_arg = '';
|
||||
if (is_array($version)) {
|
||||
$version = $version[0];
|
||||
$flush = '--flush';
|
||||
$flush_arg = '--flush';
|
||||
}
|
||||
if (!$AC['only-phpt']) {
|
||||
if (!$AC['exclude-normal']) {
|
||||
$test->add(
|
||||
new CliTestCase(
|
||||
"$phpv $version index.php --xml $flush --disable-phpt $file",
|
||||
$AC['quiet'], $size
|
||||
)
|
||||
);
|
||||
}
|
||||
if (!$AC['exclude-standalone']) {
|
||||
$test->add(
|
||||
new CliTestCase(
|
||||
"$phpv $version index.php --xml $flush --standalone --disable-phpt $file",
|
||||
$AC['quiet'], $size
|
||||
)
|
||||
);
|
||||
if ($AC['type'] !== 'phpt') {
|
||||
$break = true;
|
||||
switch ($AC['distro']) {
|
||||
case '':
|
||||
$break = false;
|
||||
case 'normal':
|
||||
$test->add(
|
||||
new CliTestCase(
|
||||
"$phpv $version index.php --xml $flush_arg $type_arg --disable-phpt $file_arg",
|
||||
$AC['quiet'], $size
|
||||
)
|
||||
);
|
||||
if ($break) break;
|
||||
case 'standalone':
|
||||
$test->add(
|
||||
new CliTestCase(
|
||||
"$phpv $version index.php --xml $flush_arg $type_arg --standalone --disable-phpt $file_arg",
|
||||
$AC['quiet'], $size
|
||||
)
|
||||
);
|
||||
if ($break) break;
|
||||
}
|
||||
}
|
||||
if (!$AC['disable-phpt']) { // naming is not consistent
|
||||
if (!$AC['disable-phpt'] && (!$AC['type'] || $AC['type'] == 'phpt')) {
|
||||
$test->add(
|
||||
new CliTestCase(
|
||||
$AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
|
||||
$AC['php'] . " index.php --xml --php \"$phpv $version\" --type=phpt",
|
||||
$AC['quiet'], $size
|
||||
)
|
||||
);
|
||||
|
@ -2,33 +2,42 @@
|
||||
|
||||
if (!defined('HTMLPurifierTest')) exit;
|
||||
|
||||
// define callable test files (sorted alphabetically)
|
||||
// These arrays are defined by this file and can be relied upon.
|
||||
$test_files = array();
|
||||
$test_dirs = array();
|
||||
$test_dirs_exclude = array();
|
||||
$vtest_dirs = array();
|
||||
$htmlt_dirs = array();
|
||||
$phpt_dirs = array();
|
||||
|
||||
if (!$AC['only-phpt']) {
|
||||
|
||||
// HTML Purifier main library
|
||||
$test_dirs[] = 'HTMLPurifier';
|
||||
$test_files[] = 'HTMLPurifierTest.php';
|
||||
|
||||
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
|
||||
if ($csstidy_location) {
|
||||
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
|
||||
}
|
||||
|
||||
// ConfigSchema Validator tests
|
||||
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
|
||||
|
||||
// ConfigDoc auxiliary library
|
||||
if (version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
|
||||
}
|
||||
|
||||
// FSTools auxiliary library
|
||||
$test_dirs[] = 'FSTools';
|
||||
$break = true;
|
||||
switch ($AC['type']) {
|
||||
case '':
|
||||
$break = false;
|
||||
case 'htmlpurifier':
|
||||
$test_dirs[] = 'HTMLPurifier';
|
||||
$test_files[] = 'HTMLPurifierTest.php';
|
||||
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
|
||||
if ($csstidy_location) {
|
||||
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
|
||||
}
|
||||
if ($break) break;
|
||||
case 'configdoc':
|
||||
if (version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
|
||||
}
|
||||
if ($break) break;
|
||||
case 'fstools':
|
||||
$test_dirs[] = 'FSTools';
|
||||
case 'htmlt':
|
||||
$htmlt_dirs[] = 'HTMLPurifier/HTMLT';
|
||||
if ($break) break;
|
||||
case 'vtest':
|
||||
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
|
||||
if ($break) break;
|
||||
|
||||
}
|
||||
|
||||
// PHPT tests
|
||||
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||
$phpt_dirs[] = 'HTMLPurifier/PHPT';
|
||||
case 'phpt':
|
||||
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||
$phpt_dirs[] = 'HTMLPurifier/PHPT';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user