Fix newline issues in tests.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / ContextTest.php
blob6172415c1c8b036e4b72a1c48e1b47d316b2ae12
1 <?php
3 // mocks
4 class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
7 protected $context;
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() {
40 $var = true;
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();
59 $var1 = 1;
60 $var2 = 2;
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
67 $array = array(
68 'var1' => &$var1,
69 'var2' => &$var2
72 $context_load->loadArray($array);
73 $this->assertIdentical($context_manual, $context_load);
75 $var1 = 10;
76 $var2 = 20;
78 $this->assertIdentical($context_manual, $context_load);