0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

[3.1.0] Fix broken autoloader, resulting in duplicate classes

- Factor out phpt directory parsing
- More phpt tests

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1561 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-02-17 23:59:23 +00:00
parent a3b6a15595
commit 40d3d5b961
6 changed files with 50 additions and 21 deletions

1
TODO
View File

@ -24,6 +24,7 @@ IMPORTANT
- Release candidate, because of the major changes - Release candidate, because of the major changes
- Move utility classes for ConfigSchema into HTML Purifier itself: they're - Move utility classes for ConfigSchema into HTML Purifier itself: they're
that important that important
- Allow unit tests to be run w/o PHPT
DOCUMENTATION DOCUMENTATION
- Document new ConfigSchema setup and format; dev-includes.txt is a base - Document new ConfigSchema setup and format; dev-includes.txt is a base

View File

@ -11,6 +11,7 @@ class HTMLPurifierExtras
$path = HTMLPurifierExtras::getPath($class); $path = HTMLPurifierExtras::getPath($class);
if (!$path) return false; if (!$path) return false;
require $path; require $path;
return true;
} }
public static function getPath($class) { public static function getPath($class) {

View File

@ -0,0 +1,19 @@
--TEST--
HTMLPurifier.auto.php without spl_autoload_register without userland autoload loading test
--SKIPIF--
<?php
if (function_exists('spl_autoload_register')) {
echo "skip - spl_autoload_register() available";
}
--FILE--
<?php
assert("!function_exists('__autoload')");
require_once '../library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
echo $purifier->purify('<b>Salsa!') . PHP_EOL;
assert("function_exists('__autoload')");
--EXPECT--
<b>Salsa!</b>

View File

@ -9,8 +9,8 @@ if (!defined('HTMLPurifierTest')) {
// is not allowed // is not allowed
function __autoload($class) { function __autoload($class) {
if (!function_exists('spl_autoload_register')) { if (!function_exists('spl_autoload_register')) {
if (class_exists('HTMLPurifier_Bootstrap', false) && HTMLPurifier_Bootstrap::autoload($class)) return true; if (HTMLPurifier_Bootstrap::autoload($class)) return true;
if (class_exists('HTMLPurifierExtras', false) && HTMLPurifierExtras::autoload($class)) return true; if (HTMLPurifierExtras::autoload($class)) return true;
} }
require str_replace('_', '/', $class) . '.php'; require str_replace('_', '/', $class) . '.php';
return true; return true;

View File

@ -35,6 +35,9 @@ $AC['only-phpt'] = false;
$aliases = array( $aliases = array(
'f' => 'file', 'f' => 'file',
); );
// It's important that this does not call the autoloader. Not a problem
// with a function, but could be if we put this in a class.
htmlpurifier_parse_args($AC, $aliases); htmlpurifier_parse_args($AC, $aliases);
if (!SimpleReporter::inCli()) { if (!SimpleReporter::inCli()) {
@ -47,17 +50,6 @@ if ($AC['disable-phpt'] && $AC['only-phpt']) {
exit(1); exit(1);
} }
if (!$AC['disable-phpt']) {
$phpt = PHPT_Registry::getInstance();
$phpt->php = $AC['php'];
}
if ($AC['flush']) {
shell_exec($AC['php'] . ' ../maintenance/generate-schema-cache.php');
shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');
shell_exec($AC['php'] . ' ../maintenance/merge-library.php');
}
// initialize and load HTML Purifier // initialize and load HTML Purifier
// use ?standalone to load the alterative standalone stub // use ?standalone to load the alterative standalone stub
if ($AC['standalone']) { if ($AC['standalone']) {
@ -71,13 +63,37 @@ if ($AC['standalone']) {
} }
require 'HTMLPurifier/Harness.php'; require 'HTMLPurifier/Harness.php';
// Shell-script code is executed
if ($AC['flush']) {
shell_exec($AC['php'] . ' ../maintenance/generate-schema-cache.php');
shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php');
shell_exec($AC['php'] . ' ../maintenance/merge-library.php');
}
// Now, userland code begins to be executed
// setup special DefinitionCacheFactory decorator // setup special DefinitionCacheFactory decorator
$factory =& HTMLPurifier_DefinitionCacheFactory::instance(); $factory =& HTMLPurifier_DefinitionCacheFactory::instance();
$factory->addDecorator('Memory'); // since we deal with a lot of config objects $factory->addDecorator('Memory'); // since we deal with a lot of config objects
if (!$AC['disable-phpt']) {
$phpt = PHPT_Registry::getInstance();
$phpt->php = $AC['php'];
}
// load tests // load tests
$test_files = array(); $test_files = array();
$phpt_dirs = array();
require 'test_files.php'; // populates $test_files array require 'test_files.php'; // populates $test_files array
// handle phpt files
foreach ($phpt_dirs as $dir) {
$FS = new FSTools();
$phpt_files = $FS->globr($dir, '*.phpt');
foreach ($phpt_files as $file) {
$test_files[] = str_replace('\\', '/', $file);
}
}
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
$test_file_lookup = array_flip($test_files); $test_file_lookup = array_flip($test_files);

View File

@ -150,12 +150,4 @@ $test_files[] = 'ConfigSchema/StringHashTest.php';
if (!$AC['disable-phpt']) { if (!$AC['disable-phpt']) {
$phpt_dirs = array(); $phpt_dirs = array();
$phpt_dirs[] = 'HTMLPurifier/PHPT'; $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);
}
}
} }