From 2dc8e9c3d58c3a498dcc5eae94c47f1de1c7de2a Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 16 Nov 2006 23:58:33 +0000 Subject: [PATCH] [1.2.0] Unit test housekeeping: - HTMLPurifier_Context doesn't throw a variable reference error if you attempt to retrieve a non-existent variable . Cleaned up test-cases to remove unnecessary swallowErrors() git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@525 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 3 +++ library/HTMLPurifier/Context.php | 3 ++- tests/HTMLPurifier/ConfigSchemaTest.php | 10 ---------- tests/HTMLPurifier/ConfigTest.php | 10 +++++----- tests/HTMLPurifier/ContextTest.php | 3 --- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index 9e127eee..92cb6c5c 100644 --- a/NEWS +++ b/NEWS @@ -24,11 +24,14 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier + Updated code-quality.txt, removing issues that have been resolved + Improved inline comments in AttrDef/Class.php, AttrDef/CSS.php and AttrDef/Host.php +- HTMLPurifier_Context doesn't throw a variable reference error if you attempt + to retrieve a non-existent variable . Switched to purify()-wide Context object registry . Refactored unit tests to minimize duplication . XSS attack sheet updated . configdoc.xml now has xml:space attached to default value nodes . Allow configuration directives to permit null values +. Cleaned up test-cases to remove unnecessary swallowErrors() 1.1.3, unknown projected release date (bugfix release, may be dropped if no major bugs are found before features) diff --git a/library/HTMLPurifier/Context.php b/library/HTMLPurifier/Context.php index 08e17655..ce6fe51e 100644 --- a/library/HTMLPurifier/Context.php +++ b/library/HTMLPurifier/Context.php @@ -34,7 +34,8 @@ class HTMLPurifier_Context if (!isset($this->_storage[$name])) { trigger_error('Attempted to retrieve non-existent variable', E_USER_ERROR); - return; + $var = null; // so we can return by reference + return $var; } return $this->_storage[$name]; } diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index 364caa91..ac9ba9ab 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -77,7 +77,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertError('Cannot define directive for undefined namespace'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -104,7 +103,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertError('Inconsistent default or type, cannot redefine'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -150,7 +148,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertError('Cannot define allowed values for undefined directive'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -192,7 +189,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertError('Cannot define alias to value that is not allowed'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -204,7 +200,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertError('Cannot define alias over allowed value'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -216,7 +211,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase $this->assertError('Invalid type for configuration directive'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -228,7 +222,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase $this->assertError('Default value does not match directive type'); $this->assertNoErrors(); - $this->swallowErrors(); @@ -239,7 +232,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase ); $this->assertNoErrors(); - $this->swallowErrors(); // define a directive with bad characters @@ -250,7 +242,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase $this->assertError('Directive name must be alphanumeric'); $this->assertNoErrors(); - $this->swallowErrors(); // define a namespace with bad characters HTMLPurifier_ConfigSchema::defineNamespace( @@ -259,7 +250,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase $this->assertError('Namespace name must be alphanumeric'); $this->assertNoErrors(); - $this->swallowErrors(); } diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index 77fa12fe..7ed4bf3e 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -66,25 +66,21 @@ class HTMLPurifier_ConfigTest extends UnitTestCase $config->get('Core', 'NotDefined'); $this->assertError('Cannot retrieve value of undefined directive'); $this->assertNoErrors(); - $this->swallowErrors(); // try to set undefined value $config->set('Foobar', 'Key', 'foobar'); $this->assertError('Cannot set undefined directive to value'); $this->assertNoErrors(); - $this->swallowErrors(); // try to set not allowed value $config->set('Extension', 'Pert', 'wizard'); $this->assertError('Value not supported'); $this->assertNoErrors(); - $this->swallowErrors(); // try to set not allowed value $config->set('Extension', 'Pert', 34); $this->assertError('Value is of invalid type'); $this->assertNoErrors(); - $this->swallowErrors(); // set aliased value $config->set('Extension', 'Pert', 'cow'); @@ -109,12 +105,16 @@ class HTMLPurifier_ConfigTest extends UnitTestCase $config->set('Extension', 'Pert', null); $this->assertError('Value is of invalid type'); $this->assertNoErrors(); - $this->swallowErrors(); } function test_getDefinition() { + // we actually want to use the old copy, because the definition + // generation routines have dependencies on configuration values + + $this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy); + $config = HTMLPurifier_Config::createDefault(); $def = $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 232c1c76..68604d5c 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -32,11 +32,9 @@ class HTMLPurifier_ContextTest extends UnitTestCase $accumulator_3 =& $this->context->get('IDAccumulator'); $this->assertError('Attempted to retrieve non-existent variable'); $this->assertNull($accumulator_3); - $this->swallowErrors(); $this->context->destroy('IDAccumulator'); $this->assertError('Attempted to destroy non-existent variable'); - $this->swallowErrors(); } @@ -48,7 +46,6 @@ class HTMLPurifier_ContextTest extends UnitTestCase $this->context->register('OnceOnly', $var); $this->assertError('Name collision, cannot re-register'); - $this->swallowErrors(); // destroy it, now registration is okay $this->context->destroy('OnceOnly');