PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / tests / HTMLPurifier / ContextTest.php
blob72d22caa1bba09c19e206ea1e86324b07476f2ac
1 <?php
3 // mocks
4 class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
7 protected $context;
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()
41 $var = true;
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();
60 $var1 = 1;
61 $var2 = 2;
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
68 $array = array(
69 'var1' => &$var1,
70 'var2' => &$var2
73 $context_load->loadArray($array);
74 $this->assertIdentical($context_manual, $context_load);
76 $var1 = 10;
77 $var2 = 20;
79 $this->assertIdentical($context_manual, $context_load);
85 // vim: et sw=4 sts=4