3 class HTMLPurifier_DefinitionCacheFactoryTest
extends HTMLPurifier_Harness
9 public function setUp()
12 $this->factory
= new HTMLPurifier_DefinitionCacheFactory();
13 $this->oldFactory
= HTMLPurifier_DefinitionCacheFactory
::instance();
14 HTMLPurifier_DefinitionCacheFactory
::instance($this->factory
);
17 public function tearDown()
19 HTMLPurifier_DefinitionCacheFactory
::instance($this->oldFactory
);
22 public function test_create()
24 $cache = $this->factory
->create('Test', $this->config
);
25 $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
28 public function test_create_withDecorator()
30 $this->factory
->addDecorator('Memory');
31 $cache = $this->factory
->create('Test', $this->config
);
32 $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
33 $ser = new HTMLPurifier_DefinitionCache_Serializer('Test');
34 $cache_real = $cache_real->decorate($ser);
35 $this->assertEqual($cache, $cache_real);
38 public function test_create_withDecoratorObject()
40 $this->factory
->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
41 $cache = $this->factory
->create('Test', $this->config
);
42 $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
43 $ser = new HTMLPurifier_DefinitionCache_Serializer('Test');
44 $cache_real = $cache_real->decorate($ser);
45 $this->assertEqual($cache, $cache_real);
48 public function test_create_recycling()
50 $cache = $this->factory
->create('Test', $this->config
);
51 $cache2 = $this->factory
->create('Test', $this->config
);
52 $this->assertReference($cache, $cache2);
55 public function test_create_invalid()
57 $this->config
->set('Cache.DefinitionImpl', 'Invalid');
58 $this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead');
59 $cache = $this->factory
->create('Test', $this->config
);
60 $this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer');
63 public function test_null()
65 $this->config
->set('Cache.DefinitionImpl', null);
66 $cache = $this->factory
->create('Test', $this->config
);
67 $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
70 public function test_register()
72 generate_mock_once('HTMLPurifier_DefinitionCache');
73 $this->config
->set('Cache.DefinitionImpl', 'TestCache');
74 $this->factory
->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock');
75 $cache = $this->factory
->create('Test', $this->config
);
76 $this->assertIsA($cache, $class);