3 class HTMLPurifier_DefinitionCacheFactoryTest
extends HTMLPurifier_Harness
9 public function setUp() {
11 $this->factory
= new HTMLPurifier_DefinitionCacheFactory();
12 $this->oldFactory
= HTMLPurifier_DefinitionCacheFactory
::instance();
13 HTMLPurifier_DefinitionCacheFactory
::instance($this->factory
);
16 public function tearDown() {
17 HTMLPurifier_DefinitionCacheFactory
::instance($this->oldFactory
);
20 function test_create() {
21 $cache = $this->factory
->create('Test', $this->config
);
22 $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
25 function test_create_withDecorator() {
26 $this->factory
->addDecorator('Memory');
27 $cache = $this->factory
->create('Test', $this->config
);
28 $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
29 $cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
30 $this->assertEqual($cache, $cache_real);
33 function test_create_withDecoratorObject() {
34 $this->factory
->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
35 $cache = $this->factory
->create('Test', $this->config
);
36 $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
37 $cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
38 $this->assertEqual($cache, $cache_real);
41 function test_create_recycling() {
42 $cache = $this->factory
->create('Test', $this->config
);
43 $cache2 = $this->factory
->create('Test', $this->config
);
44 $this->assertReference($cache, $cache2);
47 function test_create_invalid() {
48 $this->config
->set('Cache.DefinitionImpl', 'Invalid');
49 $this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead');
50 $cache = $this->factory
->create('Test', $this->config
);
51 $this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer');
54 function test_null() {
55 $this->config
->set('Cache.DefinitionImpl', null);
56 $cache = $this->factory
->create('Test', $this->config
);
57 $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
60 function test_register() {
61 generate_mock_once('HTMLPurifier_DefinitionCache');
62 $this->config
->set('Cache.DefinitionImpl', 'TestCache');
63 $this->factory
->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock');
64 $cache = $this->factory
->create('Test', $this->config
);
65 $this->assertIsA($cache, $class);