0
0
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:
Edward Z. Yang 2008-02-16 05:40:59 +00:00
parent 3441421e8b
commit 929d932234
10 changed files with 123 additions and 15 deletions

View File

@ -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);}
}

View 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>

View 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...

View 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...

View 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>

View File

@ -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 .']');
}
/**

View File

@ -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);
}
}

View File

@ -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');

View File

@ -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);
}
}
}