DefinitionCacheFactoryTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
  3. {
  4. protected $factory;
  5. protected $oldFactory;
  6. public function setUp() {
  7. parent::setup();
  8. $this->factory = new HTMLPurifier_DefinitionCacheFactory();
  9. $this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
  10. HTMLPurifier_DefinitionCacheFactory::instance($this->factory);
  11. }
  12. public function tearDown() {
  13. HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
  14. }
  15. function test_create() {
  16. $cache = $this->factory->create('Test', $this->config);
  17. $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
  18. }
  19. function test_create_withDecorator() {
  20. $this->factory->addDecorator('Memory');
  21. $cache = $this->factory->create('Test', $this->config);
  22. $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
  23. $cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
  24. $this->assertEqual($cache, $cache_real);
  25. }
  26. function test_create_withDecoratorObject() {
  27. $this->factory->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
  28. $cache = $this->factory->create('Test', $this->config);
  29. $cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
  30. $cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
  31. $this->assertEqual($cache, $cache_real);
  32. }
  33. function test_create_recycling() {
  34. $cache = $this->factory->create('Test', $this->config);
  35. $cache2 = $this->factory->create('Test', $this->config);
  36. $this->assertReference($cache, $cache2);
  37. }
  38. function test_create_invalid() {
  39. $this->config->set('Cache.DefinitionImpl', 'Invalid');
  40. $this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead');
  41. $cache = $this->factory->create('Test', $this->config);
  42. $this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer');
  43. }
  44. function test_null() {
  45. $this->config->set('Cache.DefinitionImpl', null);
  46. $cache = $this->factory->create('Test', $this->config);
  47. $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
  48. }
  49. function test_register() {
  50. generate_mock_once('HTMLPurifier_DefinitionCache');
  51. $this->config->set('Cache.DefinitionImpl', 'TestCache');
  52. $this->factory->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock');
  53. $cache = $this->factory->create('Test', $this->config);
  54. $this->assertIsA($cache, $class);
  55. }
  56. }
  57. // vim: et sw=4 sts=4