2006-08-13 18:16:30 +00:00
|
|
|
<?php
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/CSS/Composite.php';
|
2007-01-19 23:02:28 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDefHarness.php';
|
2006-08-13 18:16:30 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
|
|
|
|
HTMLPurifier_AttrDef_CSS_Composite
|
2006-08-13 21:23:57 +00:00
|
|
|
{
|
|
|
|
|
2006-08-13 21:35:06 +00:00
|
|
|
// we need to pass by ref to get the mocks in
|
2007-02-14 20:38:51 +00:00
|
|
|
function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs) {
|
2006-08-13 21:23:57 +00:00
|
|
|
$this->defs =& $defs;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
|
2006-08-13 18:16:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
var $def1, $def2;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
|
|
|
generate_mock_once('HTMLPurifier_AttrDef');
|
|
|
|
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2006-10-01 21:55:13 +00:00
|
|
|
$context = new HTMLPurifier_Context();
|
2006-08-13 18:16:30 +00:00
|
|
|
|
|
|
|
// first test: value properly validates on first definition
|
|
|
|
// so second def is never called
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$def1 = new HTMLPurifier_AttrDefMock();
|
|
|
|
$def2 = new HTMLPurifier_AttrDefMock();
|
2006-08-13 18:16:30 +00:00
|
|
|
$defs = array(&$def1, &$def2);
|
2007-02-14 20:38:51 +00:00
|
|
|
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
2006-08-13 18:16:30 +00:00
|
|
|
$input = 'FOOBAR';
|
|
|
|
$output = 'foobar';
|
|
|
|
$def1_params = array($input, $config, $context);
|
|
|
|
$def1->expectOnce('validate', $def1_params);
|
|
|
|
$def1->setReturnValue('validate', $output, $def1_params);
|
|
|
|
$def2->expectNever('validate');
|
|
|
|
|
2007-03-27 23:07:21 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2006-08-13 18:16:30 +00:00
|
|
|
|
|
|
|
$def1->tally();
|
|
|
|
$def2->tally();
|
|
|
|
|
|
|
|
// second test, first def fails, second def works
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$def1 = new HTMLPurifier_AttrDefMock();
|
|
|
|
$def2 = new HTMLPurifier_AttrDefMock();
|
2006-08-13 18:16:30 +00:00
|
|
|
$defs = array(&$def1, &$def2);
|
2007-02-14 20:38:51 +00:00
|
|
|
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
2006-08-13 18:16:30 +00:00
|
|
|
$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);
|
|
|
|
|
2007-03-27 23:15:01 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2006-08-13 18:16:30 +00:00
|
|
|
|
|
|
|
$def1->tally();
|
|
|
|
$def2->tally();
|
|
|
|
|
|
|
|
// third test, all fail, so composite faiils
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$def1 = new HTMLPurifier_AttrDefMock();
|
|
|
|
$def2 = new HTMLPurifier_AttrDefMock();
|
2006-08-13 18:16:30 +00:00
|
|
|
$defs = array(&$def1, &$def2);
|
2007-02-14 20:38:51 +00:00
|
|
|
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
2006-08-13 18:16:30 +00:00
|
|
|
$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);
|
|
|
|
|
2007-03-27 23:15:01 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2006-08-13 18:16:30 +00:00
|
|
|
|
|
|
|
$def1->tally();
|
|
|
|
$def2->tally();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|