1
0

cache.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 \Test\TestCase {
  9. /**
  10. * @var \OC\Cache cache;
  11. */
  12. protected $instance;
  13. protected function tearDown() {
  14. if($this->instance) {
  15. $this->instance->clear();
  16. }
  17. parent::tearDown();
  18. }
  19. function testSimple() {
  20. $this->assertNull($this->instance->get('value1'));
  21. $this->assertFalse($this->instance->hasKey('value1'));
  22. $value='foobar';
  23. $this->instance->set('value1', $value);
  24. $this->assertTrue($this->instance->hasKey('value1'));
  25. $received=$this->instance->get('value1');
  26. $this->assertEquals($value, $received, 'Value recieved from cache not equal to the original');
  27. $value='ipsum lorum';
  28. $this->instance->set('value1', $value);
  29. $received=$this->instance->get('value1');
  30. $this->assertEquals($value, $received, 'Value not overwritten by second set');
  31. $value2='foobar';
  32. $this->instance->set('value2', $value2);
  33. $received2=$this->instance->get('value2');
  34. $this->assertTrue($this->instance->hasKey('value1'));
  35. $this->assertTrue($this->instance->hasKey('value2'));
  36. $this->assertEquals($value, $received, 'Value changed while setting other variable');
  37. $this->assertEquals($value2, $received2, 'Second value not equal to original');
  38. $this->assertFalse($this->instance->hasKey('not_set'));
  39. $this->assertNull($this->instance->get('not_set'), 'Unset value not equal to null');
  40. $this->assertTrue($this->instance->remove('value1'));
  41. $this->assertFalse($this->instance->hasKey('value1'));
  42. }
  43. function testClear() {
  44. $value='ipsum lorum';
  45. $this->instance->set('1_value1', $value);
  46. $this->instance->set('1_value2', $value);
  47. $this->instance->set('2_value1', $value);
  48. $this->instance->set('3_value1', $value);
  49. $this->assertTrue($this->instance->clear('1_'));
  50. $this->assertFalse($this->instance->hasKey('1_value1'));
  51. $this->assertFalse($this->instance->hasKey('1_value2'));
  52. $this->assertTrue($this->instance->hasKey('2_value1'));
  53. $this->assertTrue($this->instance->hasKey('3_value1'));
  54. $this->assertTrue($this->instance->clear());
  55. $this->assertFalse($this->instance->hasKey('1_value1'));
  56. $this->assertFalse($this->instance->hasKey('1_value2'));
  57. $this->assertFalse($this->instance->hasKey('2_value1'));
  58. $this->assertFalse($this->instance->hasKey('3_value1'));
  59. }
  60. }