3 class HTMLPurifier_AttrDef_CSS_Composite_Testable
extends
4 HTMLPurifier_AttrDef_CSS_Composite
7 // we need to pass by ref to get the mocks in
8 public function __construct(&$defs)
15 class HTMLPurifier_AttrDef_CSS_CompositeTest
extends HTMLPurifier_AttrDefHarness
18 protected $def1, $def2;
20 public function test()
22 generate_mock_once('HTMLPurifier_AttrDef');
24 $config = HTMLPurifier_Config
::createDefault();
25 $context = new HTMLPurifier_Context();
27 // first test: value properly validates on first definition
28 // so second def is never called
30 $def1 = new HTMLPurifier_AttrDefMock();
31 $def2 = new HTMLPurifier_AttrDefMock();
32 $defs = array(&$def1, &$def2);
33 $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
36 $def1_params = array($input, $config, $context);
37 $def1->expectOnce('validate', $def1_params);
38 $def1->returns('validate', $output, $def1_params);
39 $def2->expectNever('validate');
41 $result = $def->validate($input, $config, $context);
42 $this->assertIdentical($output, $result);
44 // second test, first def fails, second def works
46 $def1 = new HTMLPurifier_AttrDefMock();
47 $def2 = new HTMLPurifier_AttrDefMock();
48 $defs = array(&$def1, &$def2);
49 $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
52 $def_params = array($input, $config, $context);
53 $def1->expectOnce('validate', $def_params);
54 $def1->returns('validate', false, $def_params);
55 $def2->expectOnce('validate', $def_params);
56 $def2->returns('validate', $output, $def_params);
58 $result = $def->validate($input, $config, $context);
59 $this->assertIdentical($output, $result);
61 // third test, all fail, so composite faiils
63 $def1 = new HTMLPurifier_AttrDefMock();
64 $def2 = new HTMLPurifier_AttrDefMock();
65 $defs = array(&$def1, &$def2);
66 $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
69 $def_params = array($input, $config, $context);
70 $def1->expectOnce('validate', $def_params);
71 $def1->returns('validate', false, $def_params);
72 $def2->expectOnce('validate', $def_params);
73 $def2->returns('validate', false, $def_params);
75 $result = $def->validate($input, $config, $context);
76 $this->assertIdentical($output, $result);