2007-05-29 20:21:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/DefinitionCacheFactory.php';
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
|
2007-05-29 20:21:33 +00:00
|
|
|
{
|
|
|
|
|
2007-12-09 03:14:34 +00:00
|
|
|
protected $factory;
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $oldFactory;
|
2007-05-29 20:21:33 +00:00
|
|
|
|
|
|
|
function setup() {
|
2007-12-09 03:14:34 +00:00
|
|
|
parent::setup();
|
|
|
|
$this->factory = new HTMLPurifier_DefinitionCacheFactory();
|
2007-05-29 20:21:33 +00:00
|
|
|
$this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
|
2007-12-09 03:14:34 +00:00
|
|
|
HTMLPurifier_DefinitionCacheFactory::instance($this->factory);
|
2007-05-29 20:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_create() {
|
2007-12-09 03:14:34 +00:00
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
2007-05-29 20:21:33 +00:00
|
|
|
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_create_withDecorator() {
|
2007-12-09 03:14:34 +00:00
|
|
|
$this->factory->addDecorator('Memory');
|
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
2007-05-29 20:21:33 +00:00
|
|
|
$cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
|
|
|
|
$cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
|
|
|
$this->assertEqual($cache, $cache_real);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_create_withDecoratorObject() {
|
2007-12-09 03:14:34 +00:00
|
|
|
$this->factory->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
|
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
2007-05-29 20:21:33 +00:00
|
|
|
$cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
|
|
|
|
$cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
|
|
|
$this->assertEqual($cache, $cache_real);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_create_recycling() {
|
2007-12-09 03:14:34 +00:00
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
|
|
|
$cache2 = $this->factory->create('Test', $this->config);
|
2007-05-29 20:21:33 +00:00
|
|
|
$this->assertReference($cache, $cache2);
|
|
|
|
}
|
|
|
|
|
2007-12-09 03:14:34 +00:00
|
|
|
function test_create_invalid() {
|
|
|
|
$this->config->set('Core', 'DefinitionCache', 'Invalid');
|
|
|
|
$this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead');
|
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
|
|
|
$this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer');
|
|
|
|
}
|
|
|
|
|
2007-05-29 20:21:33 +00:00
|
|
|
function test_null() {
|
2007-12-09 03:14:34 +00:00
|
|
|
$this->config->set('Core', 'DefinitionCache', null);
|
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
2007-05-29 20:21:33 +00:00
|
|
|
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
|
|
|
|
}
|
|
|
|
|
2007-12-09 03:14:34 +00:00
|
|
|
function test_register() {
|
|
|
|
generate_mock_once('HTMLPurifier_DefinitionCache');
|
|
|
|
$this->config->set('Core', 'DefinitionCache', 'TestCache');
|
|
|
|
$this->factory->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock');
|
|
|
|
$cache = $this->factory->create('Test', $this->config);
|
|
|
|
$this->assertIsA($cache, $class);
|
|
|
|
}
|
|
|
|
|
2007-05-29 20:21:33 +00:00
|
|
|
}
|
|
|
|
|