mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Implement Composite attribute definition.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@228 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
81
tests/HTMLPurifier/AttrDef/CompositeTest.php
Normal file
81
tests/HTMLPurifier/AttrDef/CompositeTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDef/Composite.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
var $def1, $def2;
|
||||
|
||||
function test() {
|
||||
|
||||
generate_mock_once('HTMLPurifier_AttrDef');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$context = new HTMLPurifier_AttrContext();
|
||||
|
||||
// first test: value properly validates on first definition
|
||||
// so second def is never called
|
||||
|
||||
$def1 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$def2 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def =& new HTMLPurifier_AttrDef_Composite($defs);
|
||||
$input = 'FOOBAR';
|
||||
$output = 'foobar';
|
||||
$def1_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def1_params);
|
||||
$def1->setReturnValue('validate', $output, $def1_params);
|
||||
$def2->expectNever('validate');
|
||||
|
||||
$this->assertIdentical($output,
|
||||
$def->validate($input, $config, $context));
|
||||
|
||||
$def1->tally();
|
||||
$def2->tally();
|
||||
|
||||
// second test, first def fails, second def works
|
||||
|
||||
$def1 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$def2 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def =& new HTMLPurifier_AttrDef_Composite($defs);
|
||||
$input = 'BOOMA';
|
||||
$output = 'booma';
|
||||
$def_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def_params);
|
||||
$def1->setReturnValue('validate', false, $def_params);
|
||||
$def2->expectOnce('validate', $def_params);
|
||||
$def2->setReturnValue('validate', $output, $def_params);
|
||||
|
||||
$this->assertIdentical($output,
|
||||
$def->validate($input, $config, $context));
|
||||
|
||||
$def1->tally();
|
||||
$def2->tally();
|
||||
|
||||
// third test, all fail, so composite faiils
|
||||
|
||||
$def1 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$def2 =& new HTMLPurifier_AttrDefMock($this);
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def =& new HTMLPurifier_AttrDef_Composite($defs);
|
||||
$input = 'BOOMA';
|
||||
$output = false;
|
||||
$def_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def_params);
|
||||
$def1->setReturnValue('validate', false, $def_params);
|
||||
$def2->expectOnce('validate', $def_params);
|
||||
$def2->setReturnValue('validate', false, $def_params);
|
||||
|
||||
$this->assertIdentical($output,
|
||||
$def->validate($input, $config, $context));
|
||||
|
||||
$def1->tally();
|
||||
$def2->tally();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user