2006-08-13 18:16:30 +00:00
|
|
|
<?php
|
|
|
|
|
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
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 21:35:06 +00:00
|
|
|
// we need to pass by ref to get the mocks in
|
2016-01-21 10:04:10 +00:00
|
|
|
public function __construct(&$defs)
|
2013-07-16 11:56:14 +00:00
|
|
|
{
|
2006-08-13 21:23:57 +00:00
|
|
|
$this->defs =& $defs;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
|
2006-08-13 18:16:30 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $def1, $def2;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function test()
|
|
|
|
{
|
2006-08-13 18:16:30 +00:00
|
|
|
generate_mock_once('HTMLPurifier_AttrDef');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2006-10-01 21:55:13 +00:00
|
|
|
$context = new HTMLPurifier_Context();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
// first test: value properly validates on first definition
|
|
|
|
// so second def is never called
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-27 23:07:21 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
// second test, first def fails, second def works
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-27 23:15:01 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
// third test, all fail, so composite faiils
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-27 23:15:01 +00:00
|
|
|
$result = $def->validate($input, $config, $context);
|
|
|
|
$this->assertIdentical($output, $result);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 18:16:30 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|