mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
[3.1.0] Implement a few phpt, fix some autoload bugs
- Make our autoload handler polite, ensuring that any __autoload() functions get added - Modify phpt calling code so that each phpt files gets its own test-case (this lets us run one phpt file at a time) - Implement phpt for loading, which test varying loading methods of HTML Purifier - Add --disable-phpt and --only-phpt flags - More descriptive veto messages, also fix test count git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1552 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
3441421e8b
commit
929d932234
@ -2,6 +2,10 @@
|
||||
|
||||
if (function_exists('spl_autoload_register')) {
|
||||
spl_autoload_register(array('HTMLPurifier_Bootstrap', 'autoload'));
|
||||
if (function_exists('__autoload')) {
|
||||
// be polite and ensure that userland autoload gets retained
|
||||
spl_autoload_register('__autoload');
|
||||
}
|
||||
} elseif (!function_exists('__autoload')) {
|
||||
function __autoload($class) {return HTMLPurifier_Bootstrap::autoload($class);}
|
||||
}
|
||||
|
11
tests/HTMLPurifier/PHPT/loading/auto-includes.phpt
Normal file
11
tests/HTMLPurifier/PHPT/loading/auto-includes.phpt
Normal file
@ -0,0 +1,11 @@
|
||||
--TEST--
|
||||
HTMLPurifier.auto.php and HTMLPurifier.includes.php loading test
|
||||
--FILE--
|
||||
<?php
|
||||
require_once '../library/HTMLPurifier.auto.php';
|
||||
require_once 'HTMLPurifier.includes.php';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
echo $purifier->purify('<b>Salsa!');
|
||||
--EXPECT--
|
||||
<b>Salsa!</b>
|
25
tests/HTMLPurifier/PHPT/loading/auto-with-autoload.phpt
Normal file
25
tests/HTMLPurifier/PHPT/loading/auto-with-autoload.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
HTMLPurifier.auto.php using spl_autoload_register with __autoload() already defined loading test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!function_exists('spl_autoload_register')) {
|
||||
echo "skip spl_autoload_register() not available";
|
||||
}
|
||||
--FILE--
|
||||
<?php
|
||||
function __autoload($class) {
|
||||
echo "Autoloading $class..." . PHP_EOL;
|
||||
eval("class $class {}");
|
||||
}
|
||||
|
||||
require_once '../library/HTMLPurifier.auto.php';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
echo $purifier->purify('<b>Salsa!') . PHP_EOL;
|
||||
|
||||
// purposely invoke older autoload
|
||||
$bar = new Bar();
|
||||
|
||||
--EXPECT--
|
||||
<b>Salsa!</b>
|
||||
Autoloading Bar...
|
25
tests/HTMLPurifier/PHPT/loading/auto-with-spl-autoload.phpt
Normal file
25
tests/HTMLPurifier/PHPT/loading/auto-with-spl-autoload.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
HTMLPurifier.auto.php using spl_autoload_register with userland spl_autoload registration loading test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!function_exists('spl_autoload_register')) {
|
||||
echo "skip spl_autoload_register() not available";
|
||||
}
|
||||
--FILE--
|
||||
<?php
|
||||
function __autoload($class) {
|
||||
echo "Autoloading $class..." . PHP_EOL;
|
||||
eval("class $class {}");
|
||||
}
|
||||
|
||||
require_once '../library/HTMLPurifier.auto.php';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
echo $purifier->purify('<b>Salsa!') . PHP_EOL;
|
||||
|
||||
// purposely invoke older autoload
|
||||
$bar = new Bar();
|
||||
|
||||
--EXPECT--
|
||||
<b>Salsa!</b>
|
||||
Autoloading Bar...
|
10
tests/HTMLPurifier/PHPT/loading/auto.phpt
Normal file
10
tests/HTMLPurifier/PHPT/loading/auto.phpt
Normal file
@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
HTMLPurifier.auto.php loading test
|
||||
--FILE--
|
||||
<?php
|
||||
require_once '../library/HTMLPurifier.auto.php';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
echo $purifier->purify('<b>Salsa!');
|
||||
--EXPECT--
|
||||
<b>Salsa!</b>
|
@ -14,33 +14,36 @@ class PHPT_Reporter_SimpleTest implements PHPT_Reporter
|
||||
$this->reporter = $reporter;
|
||||
}
|
||||
|
||||
// TODO: Figure out what the proper calls should be, since we've given
|
||||
// each Suite its own UnitTestCase controller
|
||||
|
||||
/**
|
||||
* Called when the Reporter is started from a PHPT_Suite
|
||||
* @todo Figure out if Suites can be named
|
||||
*/
|
||||
public function onSuiteStart(PHPT_Suite $suite) {
|
||||
$this->reporter->paintGroupStart('PHPT Suite', $suite->count());
|
||||
//$this->reporter->paintGroupStart('PHPT Suite', $suite->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Reporter is finished in a PHPT_Suite
|
||||
*/
|
||||
public function onSuiteEnd(PHPT_Suite $suite) {
|
||||
$this->reporter->paintGroupEnd('PHPT Suite');
|
||||
//$this->reporter->paintGroupEnd('PHPT Suite');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Case is started
|
||||
*/
|
||||
public function onCaseStart(PHPT_Case $case) {
|
||||
$this->reporter->paintCaseStart($case->name);
|
||||
//$this->reporter->paintCaseStart($case->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Case ends
|
||||
*/
|
||||
public function onCaseEnd(PHPT_Case $case) {
|
||||
$this->reporter->paintCaseEnd($case->name);
|
||||
//$this->reporter->paintCaseEnd($case->name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +57,7 @@ class PHPT_Reporter_SimpleTest implements PHPT_Reporter
|
||||
* Called when a PHPT_Case_VetoException is thrown during a Case's run()
|
||||
*/
|
||||
public function onCaseSkip(PHPT_Case $case, PHPT_Case_VetoException $veto) {
|
||||
$this->reporter->paintSkip("{$case->name} in {$case->filename}");
|
||||
$this->reporter->paintSkip($veto->getMessage() . ' [' . $case->filename .']');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,12 +120,14 @@ function htmlpurifier_args(&$AC, $aliases, $o, $v) {
|
||||
* Adds a test-class; depending on the file's extension this may involve
|
||||
* a regular UnitTestCase or a special PHPT test
|
||||
*/
|
||||
function htmlpurifier_add_test($test, $test_file) {
|
||||
$info = pathinfo($test_file);
|
||||
if (!isset($info['extension']) || $info['extension'] == 'phpt') {
|
||||
$test->addTestCase(new PHPT_Controller_SimpleTest($test_file));
|
||||
} else {
|
||||
require_once $test_file;
|
||||
$test->addTestClass(path2class($test_file));
|
||||
function htmlpurifier_add_test($test, $test_file, $only_phpt = false) {
|
||||
switch (strrchr($test_file, ".")) {
|
||||
case '.phpt':
|
||||
return $test->addTestCase(new PHPT_Controller_SimpleTest($test_file));
|
||||
case '.php':
|
||||
require_once $test_file;
|
||||
return $test->addTestClass(path2class($test_file));
|
||||
default:
|
||||
trigger_error("$test_file is an invalid file for testing", E_USER_ERROR);
|
||||
}
|
||||
}
|
@ -26,6 +26,12 @@ $AC['file'] = '';
|
||||
$AC['xml'] = false;
|
||||
$AC['dry'] = false;
|
||||
$AC['php'] = 'php';
|
||||
|
||||
// Convenience parameters for running quicker tests; ideally all tests
|
||||
// should be performed.
|
||||
$AC['disable-phpt'] = false;
|
||||
$AC['only-phpt'] = false;
|
||||
|
||||
$aliases = array(
|
||||
'f' => 'file',
|
||||
);
|
||||
@ -36,8 +42,15 @@ if (!SimpleReporter::inCli()) {
|
||||
$AC['php'] = 'php';
|
||||
}
|
||||
|
||||
$phpt = PHPT_Registry::getInstance();
|
||||
$phpt->php = $AC['php'];
|
||||
if ($AC['disable-phpt'] && $AC['only-phpt']) {
|
||||
echo "Cannot disable and allow only PHPT tests!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!$AC['disable-phpt']) {
|
||||
$phpt = PHPT_Registry::getInstance();
|
||||
$phpt->php = $AC['php'];
|
||||
}
|
||||
|
||||
// clean out cache if necessary
|
||||
if ($AC['flush']) shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');
|
||||
|
@ -4,6 +4,8 @@ if (!defined('HTMLPurifierTest')) exit;
|
||||
|
||||
// define callable test files (sorted alphabetically)
|
||||
|
||||
if (!$AC['only-phpt']) {
|
||||
|
||||
// HTML Purifier main library
|
||||
|
||||
$test_files[] = 'HTMLPurifier/AttrCollectionsTest.php';
|
||||
@ -141,6 +143,19 @@ $test_files[] = 'ConfigSchema/StringHashReverseAdapterTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashTest.php';
|
||||
|
||||
} // end if ($AC['only-phpt'])
|
||||
|
||||
// PHPT tests
|
||||
|
||||
$test_files[] = 'HTMLPurifier/PHPT';
|
||||
if (!$AC['disable-phpt']) {
|
||||
$phpt_dirs = array();
|
||||
$phpt_dirs[] = 'HTMLPurifier/PHPT';
|
||||
|
||||
foreach ($phpt_dirs as $dir) {
|
||||
$FS = new FSTools();
|
||||
$phpt_files = $FS->globr($dir, '*.phpt');
|
||||
foreach ($phpt_files as $file) {
|
||||
$test_files[] = str_replace('\\', '/', $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user