1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 06:07:26 +02:00

Refactor unit tests so that abstract test cases are now called Harnesses and AttrDef tests use their harness's assertDef() function, which enforces type much better. Also fixed a few bugs.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@161 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2006-08-05 00:30:31 +00:00
parent 6232221c08
commit 1945ddca5c
16 changed files with 100 additions and 70 deletions

View File

@@ -1,37 +1,33 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/ID.php';
require_once 'HTMLPurifier/IDAccumulator.php';
require_once 'HTMLPurifier/Config.php';
class HTMLPurifier_AttrDef_IDTest extends UnitTestCase
class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$acc = new HTMLPurifier_IDAccumulator();
$def = new HTMLPurifier_AttrDef_ID();
generate_mock_once('HTMLPurifier_Config');
$config = new HTMLPurifier_ConfigMock();
$this->id_accumulator = new HTMLPurifier_IDAccumulator();
$this->def = new HTMLPurifier_AttrDef_ID();
// valid ID names
$this->assertTrue($def->validate('alpha', $config, $acc));
$this->assertTrue($def->validate('al_ha', $config, $acc));
$this->assertTrue($def->validate('a0-:.', $config, $acc));
$this->assertTrue($def->validate('a' , $config, $acc));
$this->assertDef('alpha');
$this->assertDef('al_ha');
$this->assertDef('a0-:.');
$this->assertDef('a');
// invalid ID names
$this->assertFalse($def->validate('<asa', $config, $acc));
$this->assertFalse($def->validate('0123', $config, $acc));
$this->assertFalse($def->validate('.asa', $config, $acc));
$this->assertDef('<asa', false);
$this->assertDef('0123', false);
$this->assertDef('.asa', false);
// test duplicate detection
$this->assertFalse($def->validate('a' , $config, $acc));
$this->assertDef('a', false);
// valid once whitespace stripped, but needs to be amended
$this->assertEqual('whee', $def->validate(' whee ', $config, $acc));
$this->assertDef(' whee ', 'whee');
}