0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-03-23 14:27:02 +00:00

[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
This commit is contained in:
Edward Z. Yang 2006-11-16 23:58:33 +00:00
parent d48f9b6b21
commit 2dc8e9c3d5
5 changed files with 10 additions and 19 deletions

3
NEWS
View File

@ -24,11 +24,14 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
+ Updated code-quality.txt, removing issues that have been resolved + Updated code-quality.txt, removing issues that have been resolved
+ Improved inline comments in AttrDef/Class.php, AttrDef/CSS.php + Improved inline comments in AttrDef/Class.php, AttrDef/CSS.php
and AttrDef/Host.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 . Switched to purify()-wide Context object registry
. Refactored unit tests to minimize duplication . Refactored unit tests to minimize duplication
. XSS attack sheet updated . XSS attack sheet updated
. configdoc.xml now has xml:space attached to default value nodes . configdoc.xml now has xml:space attached to default value nodes
. Allow configuration directives to permit null values . Allow configuration directives to permit null values
. Cleaned up test-cases to remove unnecessary swallowErrors()
1.1.3, unknown projected release date 1.1.3, unknown projected release date
(bugfix release, may be dropped if no major bugs are found before features) (bugfix release, may be dropped if no major bugs are found before features)

View File

@ -34,7 +34,8 @@ class HTMLPurifier_Context
if (!isset($this->_storage[$name])) { if (!isset($this->_storage[$name])) {
trigger_error('Attempted to retrieve non-existent variable', trigger_error('Attempted to retrieve non-existent variable',
E_USER_ERROR); E_USER_ERROR);
return; $var = null; // so we can return by reference
return $var;
} }
return $this->_storage[$name]; return $this->_storage[$name];
} }

View File

@ -77,7 +77,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
); );
$this->assertError('Cannot define directive for undefined namespace'); $this->assertError('Cannot define directive for undefined namespace');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -104,7 +103,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
); );
$this->assertError('Inconsistent default or type, cannot redefine'); $this->assertError('Inconsistent default or type, cannot redefine');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -150,7 +148,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
); );
$this->assertError('Cannot define allowed values for undefined directive'); $this->assertError('Cannot define allowed values for undefined directive');
$this->assertNoErrors(); $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->assertError('Cannot define alias to value that is not allowed');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -204,7 +200,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
); );
$this->assertError('Cannot define alias over allowed value'); $this->assertError('Cannot define alias over allowed value');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -216,7 +211,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertError('Invalid type for configuration directive'); $this->assertError('Invalid type for configuration directive');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -228,7 +222,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertError('Default value does not match directive type'); $this->assertError('Default value does not match directive type');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
@ -239,7 +232,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
); );
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// define a directive with bad characters // define a directive with bad characters
@ -250,7 +242,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertError('Directive name must be alphanumeric'); $this->assertError('Directive name must be alphanumeric');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// define a namespace with bad characters // define a namespace with bad characters
HTMLPurifier_ConfigSchema::defineNamespace( HTMLPurifier_ConfigSchema::defineNamespace(
@ -259,7 +250,6 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertError('Namespace name must be alphanumeric'); $this->assertError('Namespace name must be alphanumeric');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
} }

View File

@ -66,25 +66,21 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
$config->get('Core', 'NotDefined'); $config->get('Core', 'NotDefined');
$this->assertError('Cannot retrieve value of undefined directive'); $this->assertError('Cannot retrieve value of undefined directive');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// try to set undefined value // try to set undefined value
$config->set('Foobar', 'Key', 'foobar'); $config->set('Foobar', 'Key', 'foobar');
$this->assertError('Cannot set undefined directive to value'); $this->assertError('Cannot set undefined directive to value');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// try to set not allowed value // try to set not allowed value
$config->set('Extension', 'Pert', 'wizard'); $config->set('Extension', 'Pert', 'wizard');
$this->assertError('Value not supported'); $this->assertError('Value not supported');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// try to set not allowed value // try to set not allowed value
$config->set('Extension', 'Pert', 34); $config->set('Extension', 'Pert', 34);
$this->assertError('Value is of invalid type'); $this->assertError('Value is of invalid type');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
// set aliased value // set aliased value
$config->set('Extension', 'Pert', 'cow'); $config->set('Extension', 'Pert', 'cow');
@ -109,12 +105,16 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
$config->set('Extension', 'Pert', null); $config->set('Extension', 'Pert', null);
$this->assertError('Value is of invalid type'); $this->assertError('Value is of invalid type');
$this->assertNoErrors(); $this->assertNoErrors();
$this->swallowErrors();
} }
function test_getDefinition() { 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(); $config = HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition(); $def = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');

View File

@ -32,11 +32,9 @@ class HTMLPurifier_ContextTest extends UnitTestCase
$accumulator_3 =& $this->context->get('IDAccumulator'); $accumulator_3 =& $this->context->get('IDAccumulator');
$this->assertError('Attempted to retrieve non-existent variable'); $this->assertError('Attempted to retrieve non-existent variable');
$this->assertNull($accumulator_3); $this->assertNull($accumulator_3);
$this->swallowErrors();
$this->context->destroy('IDAccumulator'); $this->context->destroy('IDAccumulator');
$this->assertError('Attempted to destroy non-existent variable'); $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->context->register('OnceOnly', $var);
$this->assertError('Name collision, cannot re-register'); $this->assertError('Name collision, cannot re-register');
$this->swallowErrors();
// destroy it, now registration is okay // destroy it, now registration is okay
$this->context->destroy('OnceOnly'); $this->context->destroy('OnceOnly');