4 class HTMLPurifier_ContextTest
extends HTMLPurifier_Harness
9 public function setUp() {
10 $this->context
= new HTMLPurifier_Context();
13 function testStandardUsage() {
15 generate_mock_once('HTMLPurifier_IDAccumulator');
17 $this->assertFalse($this->context
->exists('IDAccumulator'));
19 $accumulator = new HTMLPurifier_IDAccumulatorMock();
20 $this->context
->register('IDAccumulator', $accumulator);
21 $this->assertTrue($this->context
->exists('IDAccumulator'));
23 $accumulator_2 =& $this->context
->get('IDAccumulator');
24 $this->assertReference($accumulator, $accumulator_2);
26 $this->context
->destroy('IDAccumulator');
27 $this->assertFalse($this->context
->exists('IDAccumulator'));
29 $this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
30 $accumulator_3 =& $this->context
->get('IDAccumulator');
31 $this->assertNull($accumulator_3);
33 $this->expectError('Attempted to destroy non-existent variable IDAccumulator');
34 $this->context
->destroy('IDAccumulator');
38 function testReRegister() {
41 $this->context
->register('OnceOnly', $var);
43 $this->expectError('Name OnceOnly produces collision, cannot re-register');
44 $this->context
->register('OnceOnly', $var);
46 // destroy it, now registration is okay
47 $this->context
->destroy('OnceOnly');
48 $this->context
->register('OnceOnly', $var);
52 function test_loadArray() {
54 // references can be *really* wonky!
56 $context_manual = new HTMLPurifier_Context();
57 $context_load = new HTMLPurifier_Context();
62 $context_manual->register('var1', $var1);
63 $context_manual->register('var2', $var2);
65 // you MUST set up the references when constructing the array,
66 // otherwise the registered version will be a copy
72 $context_load->loadArray($array);
73 $this->assertIdentical($context_manual, $context_load);
78 $this->assertIdentical($context_manual, $context_load);