cache.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. abstract class Test_Cache extends UnitTestCase {
  9. /**
  10. * @var OC_Cache cache;
  11. */
  12. protected $instance;
  13. public function tearDown() {
  14. if($this->instance) {
  15. $this->instance->clear();
  16. }
  17. }
  18. function testSimple() {
  19. $this->assertNull($this->instance->get('value1'));
  20. $this->assertFalse($this->instance->hasKey('value1'));
  21. $value='foobar';
  22. $this->instance->set('value1', $value);
  23. $this->assertTrue($this->instance->hasKey('value1'));
  24. $received=$this->instance->get('value1');
  25. $this->assertEqual($value, $received, 'Value recieved from cache not equal to the original');
  26. $value='ipsum lorum';
  27. $this->instance->set('value1', $value);
  28. $received=$this->instance->get('value1');
  29. $this->assertEqual($value, $received, 'Value not overwritten by second set');
  30. $value2='foobar';
  31. $this->instance->set('value2', $value2);
  32. $received2=$this->instance->get('value2');
  33. $this->assertTrue($this->instance->hasKey('value1'));
  34. $this->assertTrue($this->instance->hasKey('value2'));
  35. $this->assertEqual($value, $received, 'Value changed while setting other variable');
  36. $this->assertEqual($value2, $received2, 'Second value not equal to original');
  37. $this->assertFalse($this->instance->hasKey('not_set'));
  38. $this->assertNull($this->instance->get('not_set'), 'Unset value not equal to null');
  39. $this->assertTrue($this->instance->remove('value1'));
  40. $this->assertFalse($this->instance->hasKey('value1'));
  41. }
  42. function testClear() {
  43. $value='ipsum lorum';
  44. $this->instance->set('1_value1', $value);
  45. $this->instance->set('1_value2', $value);
  46. $this->instance->set('2_value1', $value);
  47. $this->instance->set('3_value1', $value);
  48. $this->assertTrue($this->instance->clear('1_'));
  49. $this->assertFalse($this->instance->hasKey('1_value1'));
  50. $this->assertFalse($this->instance->hasKey('1_value2'));
  51. $this->assertTrue($this->instance->hasKey('2_value1'));
  52. $this->assertTrue($this->instance->hasKey('3_value1'));
  53. $this->assertTrue($this->instance->clear());
  54. $this->assertFalse($this->instance->hasKey('1_value1'));
  55. $this->assertFalse($this->instance->hasKey('1_value2'));
  56. $this->assertFalse($this->instance->hasKey('2_value1'));
  57. $this->assertFalse($this->instance->hasKey('3_value1'));
  58. }
  59. }