From 108df87824c5f643bfce8552380e1664882043c6 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 20 Jan 2007 19:22:55 +0000 Subject: [PATCH] Migrate from assertError to expectError, removed all assertNoErrors() git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@669 48356398-32a2-884e-a903-53898d9a118a --- tests/HTMLPurifier/AttrDef/IDTest.php | 8 ++--- .../ChildDef/StrictBlockquoteTest.php | 3 +- tests/HTMLPurifier/ConfigSchemaTest.php | 32 ++++++------------- tests/HTMLPurifier/ConfigTest.php | 22 ++++--------- tests/HTMLPurifier/ContextTest.php | 9 +++--- .../HTMLPurifier/Strategy/FixNestingTest.php | 3 +- 6 files changed, 25 insertions(+), 52 deletions(-) diff --git a/tests/HTMLPurifier/AttrDef/IDTest.php b/tests/HTMLPurifier/AttrDef/IDTest.php index 6e0e54be..e47ad9af 100644 --- a/tests/HTMLPurifier/AttrDef/IDTest.php +++ b/tests/HTMLPurifier/AttrDef/IDTest.php @@ -66,13 +66,11 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness $this->assertDef('user_story95_alas'); $this->assertDef('user_alas', 'user_story95_user_alas'); // ! + // no effect when IDPrefix isn't set $this->config->set('Attr', 'IDPrefix', ''); - $this->assertDef('amherst'); // no affect when IDPrefix isn't set - $this->assertError('%Attr.IDPrefixLocal cannot be used unless '. + $this->expectError('%Attr.IDPrefixLocal cannot be used unless '. '%Attr.IDPrefix is set'); - // SimpleTest has a bug and throws a sprintf error - // $this->assertNoErrors(); - $this->swallowErrors(); + $this->assertDef('amherst'); } diff --git a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php index a3e2cb14..27aacc81 100644 --- a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php +++ b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php @@ -38,10 +38,9 @@ extends HTMLPurifier_ChildDefHarness $this->assertResult('Needs wrap', '
Needs wrap
', array('HTML.BlockWrapper' => 'div')); + $this->expectError('Cannot use non-block element as block wrapper.'); $this->assertResult('Needs wrap', '

Needs wrap

', array('HTML.BlockWrapper' => 'dav')); - $this->assertError('Cannot use non-block element as block wrapper.'); - $this->assertNoErrors(); } diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index 7c81d480..3102e1fd 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -71,12 +71,11 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase // define a directive in an undefined namespace + $this->expectError('Cannot define directive for undefined namespace'); HTMLPurifier_ConfigSchema::define( 'Extension', 'Name', false, 'bool', 'This is for an extension, but we have not defined its namespace!' ); - $this->assertError('Cannot define directive for undefined namespace'); - $this->assertNoErrors(); @@ -86,7 +85,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase 'Core', 'Name', 'default value', 'string', $description ); $line = __LINE__; - $this->assertNoErrors(); + $directive->addDescription($file, $line, $description); $this->assertIdentical($this->our_copy->info, array( 'Core' => array( @@ -97,12 +96,11 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase // redefine a directive in an invalid manner + $this->expectError('Inconsistent default or type, cannot redefine'); HTMLPurifier_ConfigSchema::define( 'Core', 'Name', 'different default', 'string', 'Inconsistent default or type, cannot redefine' ); - $this->assertError('Inconsistent default or type, cannot redefine'); - $this->assertNoErrors(); @@ -141,13 +139,12 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase // cannot define enumeration for undefined directive + $this->expectError('Cannot define allowed values for undefined directive'); HTMLPurifier_ConfigSchema::defineAllowedValues( 'Core', 'Foobar', array( 'Real Value 9', ) ); - $this->assertError('Cannot define allowed values for undefined directive'); - $this->assertNoErrors(); @@ -182,47 +179,41 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase // cannot create alias to not-allowed value + $this->expectError('Cannot define alias to value that is not allowed'); HTMLPurifier_ConfigSchema::defineValueAliases( 'Core', 'Name', array( 'Aliased Value 3' => 'Invalid Value' ) ); - $this->assertError('Cannot define alias to value that is not allowed'); - $this->assertNoErrors(); // cannot create alias for already allowed value + $this->expectError('Cannot define alias over allowed value'); HTMLPurifier_ConfigSchema::defineValueAliases( 'Core', 'Name', array( 'Real Value' => 'Real Value 2' ) ); - $this->assertError('Cannot define alias over allowed value'); - $this->assertNoErrors(); // define a directive with an invalid type + $this->expectError('Invalid type for configuration directive'); HTMLPurifier_ConfigSchema::define( 'Core', 'Foobar', false, 'omen', 'Omen is not a valid type, so we reject this.' ); - $this->assertError('Invalid type for configuration directive'); - $this->assertNoErrors(); - // define a directive with inconsistent type + $this->expectError('Default value does not match directive type'); HTMLPurifier_ConfigSchema::define( 'Core', 'Foobaz', 10, 'string', 'If we say string, we should mean it, not integer 10.' ); - $this->assertError('Default value does not match directive type'); - $this->assertNoErrors(); - // define a directive that allows null @@ -231,25 +222,22 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase 'Nulls are allowed if you add on /null, cool huh?' ); - $this->assertNoErrors(); // define a directive with bad characters + $this->expectError('Directive name must be alphanumeric'); HTMLPurifier_ConfigSchema::define( 'Core', 'Core.Attr', 10, 'int', 'No periods! >:-(' ); - $this->assertError('Directive name must be alphanumeric'); - $this->assertNoErrors(); // define a namespace with bad characters + $this->expectError('Namespace name must be alphanumeric'); HTMLPurifier_ConfigSchema::defineNamespace( 'Foobar&Gromit', $description ); - $this->assertError('Namespace name must be alphanumeric'); - $this->assertNoErrors(); // alias related tests diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index e4634107..02e1628b 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -63,48 +63,39 @@ class HTMLPurifier_ConfigTest extends UnitTestCase $this->assertIdentical($config->get('Core', 'Key'), true); // try to retrieve undefined value + $this->expectError('Cannot retrieve value of undefined directive'); $config->get('Core', 'NotDefined'); - $this->assertError('Cannot retrieve value of undefined directive'); - $this->assertNoErrors(); // try to set undefined value + $this->expectError('Cannot set undefined directive to value'); $config->set('Foobar', 'Key', 'foobar'); - $this->assertError('Cannot set undefined directive to value'); - $this->assertNoErrors(); // try to set not allowed value + $this->expectError('Value not supported'); $config->set('Extension', 'Pert', 'wizard'); - $this->assertError('Value not supported'); - $this->assertNoErrors(); // try to set not allowed value + $this->expectError('Value is of invalid type'); $config->set('Extension', 'Pert', 34); - $this->assertError('Value is of invalid type'); - $this->assertNoErrors(); // set aliased value $config->set('Extension', 'Pert', 'cow'); - $this->assertNoErrors(); $this->assertIdentical($config->get('Extension', 'Pert'), 'moo'); // case-insensitive attempt to set value that is allowed $config->set('Core', 'Encoding', 'ISO-8859-1'); - $this->assertNoErrors(); $this->assertIdentical($config->get('Core', 'Encoding'), 'iso-8859-1'); // set null to directive that allows null $config->set('Extension', 'CanBeNull', null); - $this->assertNoErrors(); $this->assertIdentical($config->get('Extension', 'CanBeNull'), null); $config->set('Extension', 'CanBeNull', 'foobar'); - $this->assertNoErrors(); $this->assertIdentical($config->get('Extension', 'CanBeNull'), 'foobar'); // set null to directive that doesn't allow null + $this->expectError('Value is of invalid type'); $config->set('Extension', 'Pert', null); - $this->assertError('Value is of invalid type'); - $this->assertNoErrors(); // grab a namespace $config->set('Attr', 'Key', 0xBEEF); @@ -116,9 +107,8 @@ class HTMLPurifier_ConfigTest extends UnitTestCase ); // grab a non-existant namespace + $this->expectError('Cannot retrieve undefined namespace'); $config->getBatch('FurnishedGoods'); - $this->assertError('Cannot retrieve undefined namespace'); - $this->assertNoErrors(); } diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 88c0f615..195a5030 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -29,12 +29,13 @@ class HTMLPurifier_ContextTest extends UnitTestCase $this->context->destroy('IDAccumulator'); $this->assertFalse($this->context->exists('IDAccumulator')); + + $this->expectError('Attempted to retrieve non-existent variable'); $accumulator_3 =& $this->context->get('IDAccumulator'); - $this->assertError('Attempted to retrieve non-existent variable'); $this->assertNull($accumulator_3); + $this->expectError('Attempted to destroy non-existent variable'); $this->context->destroy('IDAccumulator'); - $this->assertError('Attempted to destroy non-existent variable'); } @@ -42,15 +43,13 @@ class HTMLPurifier_ContextTest extends UnitTestCase $var = true; $this->context->register('OnceOnly', $var); - $this->assertNoErrors(); + $this->expectError('Name collision, cannot re-register'); $this->context->register('OnceOnly', $var); - $this->assertError('Name collision, cannot re-register'); // destroy it, now registration is okay $this->context->destroy('OnceOnly'); $this->context->register('OnceOnly', $var); - $this->assertNoErrors(); } diff --git a/tests/HTMLPurifier/Strategy/FixNestingTest.php b/tests/HTMLPurifier/Strategy/FixNestingTest.php index a395cf07..38bd996b 100644 --- a/tests/HTMLPurifier/Strategy/FixNestingTest.php +++ b/tests/HTMLPurifier/Strategy/FixNestingTest.php @@ -91,11 +91,10 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness '
Reject
', 'Reject', array('HTML.Parent' => 'span') ); + $this->expectError('Cannot use unrecognized element as parent.'); $this->assertResult( '
Accept
', true, array('HTML.Parent' => 'script') ); - $this->assertError('Cannot use unrecognized element as parent.'); - $this->assertNoErrors(); }