From 2a002857ce5e15e7b5e98620998849d8c231bf2f Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 1 Aug 2007 14:06:59 +0000 Subject: [PATCH] [2.1.0] All unit tests inherit from HTMLPurifier_Harness, not UnitTestCase. prepareCommon() refactored to global test-case. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1332 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + tests/HTMLPurifier/AttrCollectionsTest.php | 2 +- tests/HTMLPurifier/AttrDef/URITest.php | 5 - tests/HTMLPurifier/AttrDefHarness.php | 2 +- tests/HTMLPurifier/AttrDefTest.php | 2 +- tests/HTMLPurifier/AttrTransformHarness.php | 4 +- tests/HTMLPurifier/AttrTransformTest.php | 2 +- tests/HTMLPurifier/AttrTypesTest.php | 2 +- tests/HTMLPurifier/ChildDefHarness.php | 4 +- tests/HTMLPurifier/ComplexHarness.php | 128 ++++++++++++++++++ tests/HTMLPurifier/ConfigSchemaTest.php | 2 +- tests/HTMLPurifier/ConfigTest.php | 2 +- tests/HTMLPurifier/ContextTest.php | 2 +- .../DefinitionCacheFactoryTest.php | 2 +- tests/HTMLPurifier/DefinitionCacheHarness.php | 2 +- tests/HTMLPurifier/DefinitionCacheTest.php | 2 +- tests/HTMLPurifier/DefinitionTest.php | 2 +- tests/HTMLPurifier/DoctypeRegistryTest.php | 2 +- tests/HTMLPurifier/ElementDefTest.php | 2 +- tests/HTMLPurifier/EncoderTest.php | 2 +- tests/HTMLPurifier/EntityLookupTest.php | 2 +- tests/HTMLPurifier/EntityParserTest.php | 2 +- tests/HTMLPurifier/ErrorCollectorTest.php | 2 +- tests/HTMLPurifier/ErrorsHarness.php | 2 +- tests/HTMLPurifier/GeneratorTest.php | 6 +- tests/HTMLPurifier/HTMLDefinitionTest.php | 2 +- tests/HTMLPurifier/HTMLModule/TidyTest.php | 2 +- tests/HTMLPurifier/HTMLModuleManagerTest.php | 2 +- tests/HTMLPurifier/HTMLModuleTest.php | 2 +- tests/HTMLPurifier/Harness.php | 117 +--------------- tests/HTMLPurifier/IDAccumulatorTest.php | 2 +- tests/HTMLPurifier/LanguageFactoryTest.php | 2 +- tests/HTMLPurifier/LanguageTest.php | 2 +- tests/HTMLPurifier/Lexer/DirectLexTest.php | 2 +- tests/HTMLPurifier/LexerTest.php | 2 +- tests/HTMLPurifier/PercentEncoderTest.php | 2 +- tests/HTMLPurifier/Strategy/CompositeTest.php | 2 +- tests/HTMLPurifier/StrategyHarness.php | 4 +- tests/HTMLPurifier/TagTransformTest.php | 2 +- tests/HTMLPurifier/TokenFactoryTest.php | 2 +- tests/HTMLPurifier/TokenTest.php | 2 +- tests/HTMLPurifier/URISchemeRegistryTest.php | 2 +- tests/HTMLPurifier/URISchemeTest.php | 2 +- tests/index.php | 1 + 44 files changed, 178 insertions(+), 162 deletions(-) create mode 100644 tests/HTMLPurifier/ComplexHarness.php diff --git a/NEWS b/NEWS index db24b9d7..38a1ac94 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier run the tests via command line . URI scheme is munged off if there is no authority and the scheme is the default one +. All unit tests inherit from HTMLPurifier_Harness, not UnitTestCase 2.0.1, released 2007-06-27 ! Tag auto-closing now based on a ChildDef heuristic rather than a diff --git a/tests/HTMLPurifier/AttrCollectionsTest.php b/tests/HTMLPurifier/AttrCollectionsTest.php index 06230a85..3c6774ea 100644 --- a/tests/HTMLPurifier/AttrCollectionsTest.php +++ b/tests/HTMLPurifier/AttrCollectionsTest.php @@ -8,7 +8,7 @@ Mock::generatePartial( array('performInclusions', 'expandIdentifiers') ); -class HTMLPurifier_AttrCollectionsTest extends UnitTestCase +class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness { function testConstruction() { diff --git a/tests/HTMLPurifier/AttrDef/URITest.php b/tests/HTMLPurifier/AttrDef/URITest.php index 64209fa1..fc8500b4 100644 --- a/tests/HTMLPurifier/AttrDef/URITest.php +++ b/tests/HTMLPurifier/AttrDef/URITest.php @@ -27,11 +27,6 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness HTMLPurifier_URISchemeRegistry::instance($this->oldRegistry); } - function prepareCommon(&$config, &$context) { - $config = HTMLPurifier_Config::create($config); - if (!$context) $context = new HTMLPurifier_Context(); - } - function &generateSchemeMock($scheme_names = array('http', 'mailto')) { generate_mock_once('HTMLPurifier_URIScheme'); generate_mock_once('HTMLPurifier_URISchemeRegistry'); diff --git a/tests/HTMLPurifier/AttrDefHarness.php b/tests/HTMLPurifier/AttrDefHarness.php index 39bd676d..9d811484 100644 --- a/tests/HTMLPurifier/AttrDefHarness.php +++ b/tests/HTMLPurifier/AttrDefHarness.php @@ -1,6 +1,6 @@ lexer = new HTMLPurifier_Lexer_DirectLex(); + $this->generator = new HTMLPurifier_Generator(); + parent::HTMLPurifier_Harness(); + } + + /** + * Asserts a specific result from a one parameter + config/context function + * @param $input Input parameter + * @param $expect Expectation + * @param $config Configuration array in form of Ns.Directive => Value. + * Has no effect if $this->config is set. + * @param $context_array Context array in form of Key => Value or an actual + * context object. + */ + function assertResult($input, $expect = true, + $config_array = array(), $context_array = array() + ) { + + // setup config + if ($this->config) { + $config = HTMLPurifier_Config::create($this->config); + $config->loadArray($config_array); + } else { + $config = HTMLPurifier_Config::create($config_array); + } + + // setup context object. Note that we are operating on a copy of it! + // When necessary, extend the test harness to allow post-tests + // on the context object + if (empty($this->context)) { + $context = new HTMLPurifier_Context(); + $context->loadArray($context_array); + } else { + $context =& $this->context; + } + + if ($this->to_tokens && is_string($input)) { + // $func may cause $input to change, so "clone" another copy + // to sacrifice + $input = $this->lexer->tokenizeHTML($s = $input, $config, $context); + $input_c = $this->lexer->tokenizeHTML($s, $config, $context); + } else { + $input_c = $input; + } + + // call the function + $func = $this->func; + $result = $this->obj->$func($input_c, $config, $context); + + // test a bool result + if (is_bool($result)) { + $this->assertIdentical($expect, $result); + return; + } elseif (is_bool($expect)) { + $expect = $input; + } + + if ($this->to_html) { + $result = $this->generator-> + generateFromTokens($result, $config, $context); + if (is_array($expect)) { + $expect = $this->generator-> + generateFromTokens($expect, $config, $context); + } + } + + $this->assertIdentical($expect, $result); + + } + +} + + diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index e3ef08d2..8ad8f03c 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -6,7 +6,7 @@ if (!class_exists('CS')) { class CS extends HTMLPurifier_ConfigSchema {} } -class HTMLPurifier_ConfigSchemaTest extends UnitTestCase +class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness { /** diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index a2dff2d2..941dc3da 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -6,7 +6,7 @@ if (!class_exists('CS')) { class CS extends HTMLPurifier_ConfigSchema {} } -class HTMLPurifier_ConfigTest extends UnitTestCase +class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness { var $our_copy, $old_copy; diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 8e038159..b072542f 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -5,7 +5,7 @@ require_once 'HTMLPurifier/Context.php'; // mocks require_once 'HTMLPurifier/IDAccumulator.php'; -class HTMLPurifier_ContextTest extends UnitTestCase +class HTMLPurifier_ContextTest extends HTMLPurifier_Harness { var $context; diff --git a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php index beabc33c..a2768d7b 100644 --- a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php +++ b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/DefinitionCacheFactory.php'; -class HTMLPurifier_DefinitionCacheFactoryTest extends UnitTestCase +class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness { var $newFactory; diff --git a/tests/HTMLPurifier/DefinitionCacheHarness.php b/tests/HTMLPurifier/DefinitionCacheHarness.php index 7304ecdd..e6bd839f 100644 --- a/tests/HTMLPurifier/DefinitionCacheHarness.php +++ b/tests/HTMLPurifier/DefinitionCacheHarness.php @@ -1,6 +1,6 @@ UnitTestCase(); + $this->HTMLPurifier_Harness(); $this->gen = new HTMLPurifier_Generator(); $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); } diff --git a/tests/HTMLPurifier/HTMLDefinitionTest.php b/tests/HTMLPurifier/HTMLDefinitionTest.php index f18ecb15..d64daf6f 100644 --- a/tests/HTMLPurifier/HTMLDefinitionTest.php +++ b/tests/HTMLPurifier/HTMLDefinitionTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/HTMLDefinition.php'; -class HTMLPurifier_HTMLDefinitionTest extends UnitTestCase +class HTMLPurifier_HTMLDefinitionTest extends HTMLPurifier_Harness { function test_parseTinyMCEAllowedList() { diff --git a/tests/HTMLPurifier/HTMLModule/TidyTest.php b/tests/HTMLPurifier/HTMLModule/TidyTest.php index ff8d844d..f2522d9d 100644 --- a/tests/HTMLPurifier/HTMLModule/TidyTest.php +++ b/tests/HTMLPurifier/HTMLModule/TidyTest.php @@ -8,7 +8,7 @@ Mock::generatePartial( array('makeFixes', 'makeFixesForLevel', 'populate') ); -class HTMLPurifier_HTMLModule_TidyTest extends UnitTestCase +class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness { function test_getFixesForLevel() { diff --git a/tests/HTMLPurifier/HTMLModuleManagerTest.php b/tests/HTMLPurifier/HTMLModuleManagerTest.php index d5219ca1..50dcb154 100644 --- a/tests/HTMLPurifier/HTMLModuleManagerTest.php +++ b/tests/HTMLPurifier/HTMLModuleManagerTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/HTMLModuleManager.php'; -class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase +class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness { function test_addModule() { diff --git a/tests/HTMLPurifier/HTMLModuleTest.php b/tests/HTMLPurifier/HTMLModuleTest.php index 238ca42a..ace5805f 100644 --- a/tests/HTMLPurifier/HTMLModuleTest.php +++ b/tests/HTMLPurifier/HTMLModuleTest.php @@ -3,7 +3,7 @@ require_once 'HTMLPurifier/HTMLModule.php'; require_once 'HTMLPurifier/AttrDef.php'; -class HTMLPurifier_HTMLModuleTest extends UnitTestCase +class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness { function test_addElementToContentSet() { diff --git a/tests/HTMLPurifier/Harness.php b/tests/HTMLPurifier/Harness.php index 84cea5eb..ce1bb11e 100644 --- a/tests/HTMLPurifier/Harness.php +++ b/tests/HTMLPurifier/Harness.php @@ -1,128 +1,19 @@ lexer = new HTMLPurifier_Lexer_DirectLex(); - $this->generator = new HTMLPurifier_Generator(); parent::UnitTestCase(); } - /** - * Asserts a specific result from a one parameter + config/context function - * @param $input Input parameter - * @param $expect Expectation - * @param $config Configuration array in form of Ns.Directive => Value. - * Has no effect if $this->config is set. - * @param $context_array Context array in form of Key => Value or an actual - * context object. - */ - function assertResult($input, $expect = true, - $config_array = array(), $context_array = array() - ) { - - // setup config - if ($this->config) { - $config = HTMLPurifier_Config::create($this->config); - $config->loadArray($config_array); - } else { - $config = HTMLPurifier_Config::create($config_array); - } - - // setup context object. Note that we are operating on a copy of it! - // When necessary, extend the test harness to allow post-tests - // on the context object - if (empty($this->context)) { - $context = new HTMLPurifier_Context(); - $context->loadArray($context_array); - } else { - $context =& $this->context; - } - - if ($this->to_tokens && is_string($input)) { - // $func may cause $input to change, so "clone" another copy - // to sacrifice - $input = $this->lexer->tokenizeHTML($s = $input, $config, $context); - $input_c = $this->lexer->tokenizeHTML($s, $config, $context); - } else { - $input_c = $input; - } - - // call the function - $func = $this->func; - $result = $this->obj->$func($input_c, $config, $context); - - // test a bool result - if (is_bool($result)) { - $this->assertIdentical($expect, $result); - return; - } elseif (is_bool($expect)) { - $expect = $input; - } - - if ($this->to_html) { - $result = $this->generator-> - generateFromTokens($result, $config, $context); - if (is_array($expect)) { - $expect = $this->generator-> - generateFromTokens($expect, $config, $context); - } - } - - $this->assertIdentical($expect, $result); - + function prepareCommon(&$config, &$context) { + $config = HTMLPurifier_Config::create($config); + if (!$context) $context = new HTMLPurifier_Context(); } } - diff --git a/tests/HTMLPurifier/IDAccumulatorTest.php b/tests/HTMLPurifier/IDAccumulatorTest.php index 05db0b2a..006d689c 100644 --- a/tests/HTMLPurifier/IDAccumulatorTest.php +++ b/tests/HTMLPurifier/IDAccumulatorTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/IDAccumulator.php'; -class HTMLPurifier_IDAccumulatorTest extends UnitTestCase +class HTMLPurifier_IDAccumulatorTest extends HTMLPurifier_Harness { function test() { diff --git a/tests/HTMLPurifier/LanguageFactoryTest.php b/tests/HTMLPurifier/LanguageFactoryTest.php index eb0f4556..2cadb1c1 100644 --- a/tests/HTMLPurifier/LanguageFactoryTest.php +++ b/tests/HTMLPurifier/LanguageFactoryTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/LanguageFactory.php'; -class HTMLPurifier_LanguageFactoryTest extends UnitTestCase +class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness { function test() { diff --git a/tests/HTMLPurifier/LanguageTest.php b/tests/HTMLPurifier/LanguageTest.php index f846c619..ec4244a8 100644 --- a/tests/HTMLPurifier/LanguageTest.php +++ b/tests/HTMLPurifier/LanguageTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/Language.php'; -class HTMLPurifier_LanguageTest extends UnitTestCase +class HTMLPurifier_LanguageTest extends HTMLPurifier_Harness { var $lang; diff --git a/tests/HTMLPurifier/Lexer/DirectLexTest.php b/tests/HTMLPurifier/Lexer/DirectLexTest.php index a9154093..37835790 100644 --- a/tests/HTMLPurifier/Lexer/DirectLexTest.php +++ b/tests/HTMLPurifier/Lexer/DirectLexTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/Lexer/DirectLex.php'; -class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase +class HTMLPurifier_Lexer_DirectLexTest extends HTMLPurifier_Harness { var $DirectLex; diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index 2fd10268..9123bf6c 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/Lexer/DirectLex.php'; -class HTMLPurifier_LexerTest extends UnitTestCase +class HTMLPurifier_LexerTest extends HTMLPurifier_Harness { var $Lexer; diff --git a/tests/HTMLPurifier/PercentEncoderTest.php b/tests/HTMLPurifier/PercentEncoderTest.php index ea52021d..4b01ac3a 100644 --- a/tests/HTMLPurifier/PercentEncoderTest.php +++ b/tests/HTMLPurifier/PercentEncoderTest.php @@ -2,7 +2,7 @@ require_once 'HTMLPurifier/PercentEncoder.php'; -class HTMLPurifier_PercentEncoderTest extends UnitTestCase +class HTMLPurifier_PercentEncoderTest extends HTMLPurifier_Harness { var $PercentEncoder; diff --git a/tests/HTMLPurifier/Strategy/CompositeTest.php b/tests/HTMLPurifier/Strategy/CompositeTest.php index 606d786b..db4ab040 100644 --- a/tests/HTMLPurifier/Strategy/CompositeTest.php +++ b/tests/HTMLPurifier/Strategy/CompositeTest.php @@ -15,7 +15,7 @@ class HTMLPurifier_Strategy_Composite_Test } // doesn't use Strategy harness -class HTMLPurifier_Strategy_CompositeTest extends UnitTestCase +class HTMLPurifier_Strategy_CompositeTest extends HTMLPurifier_Harness { function test() { diff --git a/tests/HTMLPurifier/StrategyHarness.php b/tests/HTMLPurifier/StrategyHarness.php index d8b2d5fd..72b3c22c 100644 --- a/tests/HTMLPurifier/StrategyHarness.php +++ b/tests/HTMLPurifier/StrategyHarness.php @@ -1,8 +1,8 @@