mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-05 06:01:52 +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.
|
the strategy to be used, standalone, on untrusted input.
|
||||||
! %Core.AggressivelyFixLt is on by default. This causes more sensible
|
! %Core.AggressivelyFixLt is on by default. This causes more sensible
|
||||||
processing of left angled brackets in smileys and other whatnot.
|
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,
|
- Fix two bugs in %URI.MakeAbsolute; one involving empty paths in base URLs,
|
||||||
the other involving an undefined $is_folder error.
|
the other involving an undefined $is_folder error.
|
||||||
- Throw error when %Core.Encoding is set to a spurious value. Previously,
|
- 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.
|
index to reprocess tokens.
|
||||||
. StringHashParser now allows for multiline sections with "empty" content;
|
. StringHashParser now allows for multiline sections with "empty" content;
|
||||||
previously the section would remain undefined.
|
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
|
3.1.1, released 2008-06-19
|
||||||
# %URI.Munge now, by default, does not munge resources (for example, <img src="">)
|
# %URI.Munge now, by default, does not munge resources (for example, <img src="">)
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
* - file (f), a single file to test
|
* - file (f), a single file to test
|
||||||
* - xml, whether or not to output XML
|
* - xml, whether or not to output XML
|
||||||
* - dry, whether or not to do a dry run
|
* - 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
|
* 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
|
* ../test-settings.sample.php, copy the file to test-settings.php and follow
|
||||||
@ -38,10 +40,9 @@ $AC['xml'] = false;
|
|||||||
$AC['dry'] = false;
|
$AC['dry'] = false;
|
||||||
$AC['php'] = $php;
|
$AC['php'] = $php;
|
||||||
|
|
||||||
// Convenience parameters for running quicker tests; ideally all tests
|
$AC['type'] = '';
|
||||||
// should be performed.
|
|
||||||
$AC['disable-phpt'] = false;
|
$AC['disable-phpt'] = false;
|
||||||
$AC['only-phpt'] = false;
|
$AC['only-phpt'] = false; // alias for --type=phpt
|
||||||
|
|
||||||
$aliases = array(
|
$aliases = array(
|
||||||
'f' => 'file',
|
'f' => 'file',
|
||||||
@ -52,18 +53,18 @@ $aliases = array(
|
|||||||
htmlpurifier_parse_args($AC, $aliases);
|
htmlpurifier_parse_args($AC, $aliases);
|
||||||
|
|
||||||
// Disable PHPT tests if they're not enabled
|
// 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()) {
|
if (!SimpleReporter::inCli()) {
|
||||||
// Undo any dangerous parameters
|
// Undo any dangerous parameters
|
||||||
$AC['php'] = $php;
|
$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
|
// Shell-script code is executed
|
||||||
|
|
||||||
if ($AC['xml']) {
|
if ($AC['xml']) {
|
||||||
@ -102,14 +103,7 @@ if (!$AC['disable-phpt']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load tests
|
// load tests
|
||||||
|
require 'test_files.php';
|
||||||
$test_files = array();
|
|
||||||
$test_dirs = array();
|
|
||||||
$test_dirs_exclude = array();
|
|
||||||
$vtest_dirs = array();
|
|
||||||
$phpt_dirs = array();
|
|
||||||
|
|
||||||
require 'test_files.php'; // populates $test_files array
|
|
||||||
|
|
||||||
$FS = new FSTools();
|
$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);
|
array_unique($test_files);
|
||||||
sort($test_files); // for the SELECT
|
sort($test_files); // for the SELECT
|
||||||
$GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
|
$GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
*
|
*
|
||||||
* This file tests HTML Purifier in all versions of PHP. Arguments
|
* This file tests HTML Purifier in all versions of PHP. Arguments
|
||||||
* are specified like --arg=opt, allowed arguments are:
|
* 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
|
* - quiet (q), if specified no informative messages are enabled (please use
|
||||||
* this if you're outputting XML)
|
* 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
|
* @note
|
||||||
* It requires a script called phpv that takes an extra argument (the
|
* It requires a script called phpv that takes an extra argument (the
|
||||||
@ -24,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
define('HTMLPurifierTest', 1);
|
define('HTMLPurifierTest', 1);
|
||||||
|
chdir(dirname(__FILE__));
|
||||||
$php = 'php'; // for safety
|
$php = 'php'; // for safety
|
||||||
|
|
||||||
require_once 'common.php';
|
require_once 'common.php';
|
||||||
@ -34,20 +37,34 @@ if (!SimpleReporter::inCli()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$AC = array(); // parameters
|
$AC = array(); // parameters
|
||||||
$AC['exclude-normal'] = false;
|
|
||||||
$AC['exclude-standalone'] = false;
|
|
||||||
$AC['file'] = '';
|
$AC['file'] = '';
|
||||||
$AC['xml'] = false;
|
$AC['xml'] = false;
|
||||||
$AC['quiet'] = false;
|
$AC['quiet'] = false;
|
||||||
$AC['php'] = $php;
|
$AC['php'] = $php;
|
||||||
$AC['disable-phpt'] = false;
|
$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(
|
$aliases = array(
|
||||||
'f' => 'file',
|
'f' => 'file',
|
||||||
'q' => 'quiet',
|
'q' => 'quiet',
|
||||||
);
|
);
|
||||||
htmlpurifier_parse_args($AC, $aliases);
|
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']) {
|
if ($AC['xml']) {
|
||||||
$reporter = new XmlReporter();
|
$reporter = new XmlReporter();
|
||||||
} else {
|
} else {
|
||||||
@ -55,16 +72,14 @@ if ($AC['xml']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Regenerate any necessary files
|
// Regenerate any necessary files
|
||||||
htmlpurifier_flush($AC['php'], $reporter);
|
if (!$AC['disable-flush']) htmlpurifier_flush($AC['php'], $reporter);
|
||||||
|
|
||||||
$file = '';
|
$file_arg = '';
|
||||||
|
|
||||||
$test_files = array();
|
|
||||||
require 'test_files.php';
|
require 'test_files.php';
|
||||||
if ($AC['file']) {
|
if ($AC['file']) {
|
||||||
$test_files_lookup = array_flip($test_files);
|
$test_files_lookup = array_flip($test_files);
|
||||||
if (isset($test_files_lookup[$AC['file']])) {
|
if (isset($test_files_lookup[$AC['file']])) {
|
||||||
$file = '--file=' . $AC['file'];
|
$file_arg = '--file=' . $AC['file'];
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Invalid file passed");
|
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.
|
// This allows us to get out of having to do dry runs.
|
||||||
$size = count($test_files);
|
$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
|
// Setup the test
|
||||||
$test = new TestSuite('HTML Purifier Multiple Versions Test');
|
$test = new TestSuite('HTML Purifier Multiple Versions Test');
|
||||||
foreach ($versions_to_test as $version) {
|
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)) {
|
if (is_array($version)) {
|
||||||
$version = $version[0];
|
$version = $version[0];
|
||||||
$flush = '--flush';
|
$flush_arg = '--flush';
|
||||||
}
|
}
|
||||||
if (!$AC['only-phpt']) {
|
if ($AC['type'] !== 'phpt') {
|
||||||
if (!$AC['exclude-normal']) {
|
$break = true;
|
||||||
|
switch ($AC['distro']) {
|
||||||
|
case '':
|
||||||
|
$break = false;
|
||||||
|
case 'normal':
|
||||||
$test->add(
|
$test->add(
|
||||||
new CliTestCase(
|
new CliTestCase(
|
||||||
"$phpv $version index.php --xml $flush --disable-phpt $file",
|
"$phpv $version index.php --xml $flush_arg $type_arg --disable-phpt $file_arg",
|
||||||
$AC['quiet'], $size
|
$AC['quiet'], $size
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
if ($break) break;
|
||||||
if (!$AC['exclude-standalone']) {
|
case 'standalone':
|
||||||
$test->add(
|
$test->add(
|
||||||
new CliTestCase(
|
new CliTestCase(
|
||||||
"$phpv $version index.php --xml $flush --standalone --disable-phpt $file",
|
"$phpv $version index.php --xml $flush_arg $type_arg --standalone --disable-phpt $file_arg",
|
||||||
$AC['quiet'], $size
|
$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(
|
$test->add(
|
||||||
new CliTestCase(
|
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
|
$AC['quiet'], $size
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -2,33 +2,42 @@
|
|||||||
|
|
||||||
if (!defined('HTMLPurifierTest')) exit;
|
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']) {
|
$break = true;
|
||||||
|
switch ($AC['type']) {
|
||||||
// HTML Purifier main library
|
case '':
|
||||||
|
$break = false;
|
||||||
|
case 'htmlpurifier':
|
||||||
$test_dirs[] = 'HTMLPurifier';
|
$test_dirs[] = 'HTMLPurifier';
|
||||||
$test_files[] = 'HTMLPurifierTest.php';
|
$test_files[] = 'HTMLPurifierTest.php';
|
||||||
|
|
||||||
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
|
$test_dirs_exclude['HTMLPurifier/Filter/ExtractStyleBlocksTest.php'] = true;
|
||||||
if ($csstidy_location) {
|
if ($csstidy_location) {
|
||||||
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
|
$test_files[] = 'HTMLPurifier/Filter/ExtractStyleBlocksTest.php';
|
||||||
}
|
}
|
||||||
|
if ($break) break;
|
||||||
// ConfigSchema Validator tests
|
case 'configdoc':
|
||||||
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
|
|
||||||
|
|
||||||
// ConfigDoc auxiliary library
|
|
||||||
if (version_compare(PHP_VERSION, '5.2', '>=')) {
|
if (version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||||
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
|
// $test_dirs[] = 'ConfigDoc'; // no test files currently!
|
||||||
}
|
}
|
||||||
|
if ($break) break;
|
||||||
// FSTools auxiliary library
|
case 'fstools':
|
||||||
$test_dirs[] = 'FSTools';
|
$test_dirs[] = 'FSTools';
|
||||||
|
case 'htmlt':
|
||||||
|
$htmlt_dirs[] = 'HTMLPurifier/HTMLT';
|
||||||
|
if ($break) break;
|
||||||
|
case 'vtest':
|
||||||
|
$vtest_dirs[] = 'HTMLPurifier/ConfigSchema/Validator';
|
||||||
|
if ($break) break;
|
||||||
|
|
||||||
}
|
case 'phpt':
|
||||||
|
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
|
||||||
// PHPT tests
|
|
||||||
if (!$AC['disable-phpt'] && version_compare(PHP_VERSION, '5.2', '>=')) {
|
|
||||||
$phpt_dirs[] = 'HTMLPurifier/PHPT';
|
$phpt_dirs[] = 'HTMLPurifier/PHPT';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user