3 generate_mock_once('HTMLPurifier_DefinitionCache');
5 class HTMLPurifier_DefinitionCache_Decorator_MemoryTest
extends HTMLPurifier_DefinitionCache_DecoratorHarness
8 public function setup()
10 $this->cache
= new HTMLPurifier_DefinitionCache_Decorator_Memory();
14 public function setupMockForSuccess($op)
16 $this->mock
->expectOnce($op, array($this->def
, $this->config
));
17 $this->mock
->setReturnValue($op, true, array($this->def
, $this->config
));
18 $this->mock
->expectNever('get');
21 public function setupMockForFailure($op)
23 $this->mock
->expectOnce($op, array($this->def
, $this->config
));
24 $this->mock
->setReturnValue($op, false, array($this->def
, $this->config
));
25 $this->mock
->expectOnce('get', array($this->config
));
28 public function test_get()
30 $this->mock
->expectOnce('get', array($this->config
)); // only ONE call!
31 $this->mock
->setReturnValue('get', $this->def
, array($this->config
));
32 $this->assertEqual($this->cache
->get($this->config
), $this->def
);
33 $this->assertEqual($this->cache
->get($this->config
), $this->def
);
36 public function test_set()
38 $this->setupMockForSuccess('set', 'get');
39 $this->assertEqual($this->cache
->set($this->def
, $this->config
), true);
40 $this->assertEqual($this->cache
->get($this->config
), $this->def
);
43 public function test_set_failure()
45 $this->setupMockForFailure('set', 'get');
46 $this->assertEqual($this->cache
->set($this->def
, $this->config
), false);
47 $this->cache
->get($this->config
);
50 public function test_replace()
52 $this->setupMockForSuccess('replace', 'get');
53 $this->assertEqual($this->cache
->replace($this->def
, $this->config
), true);
54 $this->assertEqual($this->cache
->get($this->config
), $this->def
);
57 public function test_replace_failure()
59 $this->setupMockForFailure('replace', 'get');
60 $this->assertEqual($this->cache
->replace($this->def
, $this->config
), false);
61 $this->cache
->get($this->config
);
64 public function test_add()
66 $this->setupMockForSuccess('add', 'get');
67 $this->assertEqual($this->cache
->add($this->def
, $this->config
), true);
68 $this->assertEqual($this->cache
->get($this->config
), $this->def
);
71 public function test_add_failure()
73 $this->setupMockForFailure('add', 'get');
74 $this->assertEqual($this->cache
->add($this->def
, $this->config
), false);
75 $this->cache
->get($this->config
);