4 class HTMLPurifier_ContextTest
extends HTMLPurifier_Harness
9 public function setUp()
11 $this->context
= new HTMLPurifier_Context();
14 public function testStandardUsage()
16 generate_mock_once('HTMLPurifier_IDAccumulator');
18 $this->assertFalse($this->context
->exists('IDAccumulator'));
20 $accumulator = new HTMLPurifier_IDAccumulatorMock();
21 $this->context
->register('IDAccumulator', $accumulator);
22 $this->assertTrue($this->context
->exists('IDAccumulator'));
24 $accumulator_2 =& $this->context
->get('IDAccumulator');
25 $this->assertReference($accumulator, $accumulator_2);
27 $this->context
->destroy('IDAccumulator');
28 $this->assertFalse($this->context
->exists('IDAccumulator'));
30 $this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
31 $accumulator_3 =& $this->context
->get('IDAccumulator');
32 $this->assertNull($accumulator_3);
34 $this->expectError('Attempted to destroy non-existent variable IDAccumulator');
35 $this->context
->destroy('IDAccumulator');
39 public function testReRegister()
42 $this->context
->register('OnceOnly', $var);
44 $this->expectError('Name OnceOnly produces collision, cannot re-register');
45 $this->context
->register('OnceOnly', $var);
47 // destroy it, now registration is okay
48 $this->context
->destroy('OnceOnly');
49 $this->context
->register('OnceOnly', $var);
53 public function test_loadArray()
55 // references can be *really* wonky!
57 $context_manual = new HTMLPurifier_Context();
58 $context_load = new HTMLPurifier_Context();
63 $context_manual->register('var1', $var1);
64 $context_manual->register('var2', $var2);
66 // you MUST set up the references when constructing the array,
67 // otherwise the registered version will be a copy
73 $context_load->loadArray($array);
74 $this->assertIdentical($context_manual, $context_load);
79 $this->assertIdentical($context_manual, $context_load);
83 public function testNull() {
84 $context = new HTMLPurifier_Context();
86 $context->register('var', $var);
87 $this->assertNull($context->get('var'));
88 $context->destroy('var');