3 require_once 'HTMLPurifier/Context.php';
6 require_once 'HTMLPurifier/IDAccumulator.php';
8 class HTMLPurifier_ContextTest
extends UnitTestCase
14 $this->context
= new HTMLPurifier_Context();
17 function testStandardUsage() {
19 generate_mock_once('HTMLPurifier_IDAccumulator');
21 $accumulator =& new HTMLPurifier_IDAccumulatorMock($this);
22 $this->context
->register('IDAccumulator', $accumulator);
24 $accumulator_2 =& $this->context
->get('IDAccumulator');
25 $this->assertReference($accumulator, $accumulator_2);
27 $this->context
->destroy('IDAccumulator');
28 $accumulator_3 =& $this->context
->get('IDAccumulator');
29 $this->assertError('Attempted to retrieve non-existent variable');
30 $this->assertNull($accumulator_3);
31 $this->swallowErrors();
33 $this->context
->destroy('IDAccumulator');
34 $this->assertError('Attempted to destroy non-existent variable');
35 $this->swallowErrors();
39 function testReRegister() {
42 $this->context
->register('OnceOnly', $var);
43 $this->assertNoErrors();
45 $this->context
->register('OnceOnly', $var);
46 $this->assertError('Name collision, cannot re-register');
47 $this->swallowErrors();
49 // destroy it, now registration is okay
50 $this->context
->destroy('OnceOnly');
51 $this->context
->register('OnceOnly', $var);
52 $this->assertNoErrors();