From 40d3d5b9613fafb4342aa6d6757a80de7dbbd6a7 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 17 Feb 2008 23:59:23 +0000 Subject: [PATCH] [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 --- TODO | 1 + extras/HTMLPurifierExtras.php | 1 + .../loading/auto-without-spl-autoload.phpt | 19 ++++++++++ tests/common.php | 4 +- tests/index.php | 38 +++++++++++++------ tests/test_files.php | 8 ---- 6 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 tests/HTMLPurifier/PHPT/loading/auto-without-spl-autoload.phpt diff --git a/TODO b/TODO index c43b7a13..30280ea8 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,7 @@ IMPORTANT - Release candidate, because of the major changes - Move utility classes for ConfigSchema into HTML Purifier itself: they're that important + - Allow unit tests to be run w/o PHPT DOCUMENTATION - Document new ConfigSchema setup and format; dev-includes.txt is a base diff --git a/extras/HTMLPurifierExtras.php b/extras/HTMLPurifierExtras.php index 8a489307..10d5b6df 100644 --- a/extras/HTMLPurifierExtras.php +++ b/extras/HTMLPurifierExtras.php @@ -11,6 +11,7 @@ class HTMLPurifierExtras $path = HTMLPurifierExtras::getPath($class); if (!$path) return false; require $path; + return true; } public static function getPath($class) { diff --git a/tests/HTMLPurifier/PHPT/loading/auto-without-spl-autoload.phpt b/tests/HTMLPurifier/PHPT/loading/auto-without-spl-autoload.phpt new file mode 100644 index 00000000..a05a2fe1 --- /dev/null +++ b/tests/HTMLPurifier/PHPT/loading/auto-without-spl-autoload.phpt @@ -0,0 +1,19 @@ +--TEST-- +HTMLPurifier.auto.php without spl_autoload_register without userland autoload loading test +--SKIPIF-- +purify('Salsa!') . PHP_EOL; +assert("function_exists('__autoload')"); + +--EXPECT-- +Salsa! + diff --git a/tests/common.php b/tests/common.php index 6dbba861..dabc2d6d 100644 --- a/tests/common.php +++ b/tests/common.php @@ -9,8 +9,8 @@ if (!defined('HTMLPurifierTest')) { // is not allowed function __autoload($class) { if (!function_exists('spl_autoload_register')) { - if (class_exists('HTMLPurifier_Bootstrap', false) && HTMLPurifier_Bootstrap::autoload($class)) return true; - if (class_exists('HTMLPurifierExtras', false) && HTMLPurifierExtras::autoload($class)) return true; + if (HTMLPurifier_Bootstrap::autoload($class)) return true; + if (HTMLPurifierExtras::autoload($class)) return true; } require str_replace('_', '/', $class) . '.php'; return true; diff --git a/tests/index.php b/tests/index.php index 59dd2412..5d9eb663 100755 --- a/tests/index.php +++ b/tests/index.php @@ -35,6 +35,9 @@ $AC['only-phpt'] = false; $aliases = array( '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); if (!SimpleReporter::inCli()) { @@ -47,17 +50,6 @@ if ($AC['disable-phpt'] && $AC['only-phpt']) { 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 // use ?standalone to load the alterative standalone stub if ($AC['standalone']) { @@ -71,13 +63,37 @@ if ($AC['standalone']) { } 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 $factory =& HTMLPurifier_DefinitionCacheFactory::instance(); $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 $test_files = array(); +$phpt_dirs = 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 $GLOBALS['HTMLPurifierTest']['Files'] = $test_files; // for the reporter $test_file_lookup = array_flip($test_files); diff --git a/tests/test_files.php b/tests/test_files.php index d8d0faf8..90b71de2 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -150,12 +150,4 @@ $test_files[] = 'ConfigSchema/StringHashTest.php'; 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); - } - } }