You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7KB

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