TestCache.php 2.4 KB

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