Session.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright (c) 2013 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\Session;
  9. abstract class Session extends \Test\TestCase {
  10. /**
  11. * @var \OC\Session\Session
  12. */
  13. protected $instance;
  14. protected function tearDown(): void {
  15. $this->instance->clear();
  16. parent::tearDown();
  17. }
  18. public function testNotExistsEmpty() {
  19. $this->assertFalse($this->instance->exists('foo'));
  20. }
  21. public function testExistsAfterSet() {
  22. $this->instance->set('foo', 1);
  23. $this->assertTrue($this->instance->exists('foo'));
  24. }
  25. public function testNotExistsAfterRemove() {
  26. $this->instance->set('foo', 1);
  27. $this->instance->remove('foo');
  28. $this->assertFalse($this->instance->exists('foo'));
  29. }
  30. public function testGetNonExisting() {
  31. $this->assertNull($this->instance->get('foo'));
  32. }
  33. public function testGetAfterSet() {
  34. $this->instance->set('foo', 'bar');
  35. $this->assertEquals('bar', $this->instance->get(('foo')));
  36. }
  37. public function testRemoveNonExisting() {
  38. $this->assertFalse($this->instance->exists('foo'));
  39. $this->instance->remove('foo');
  40. $this->assertFalse($this->instance->exists('foo'));
  41. }
  42. public function testNotExistsAfterClear() {
  43. $this->instance->set('foo', 1);
  44. $this->instance->clear();
  45. $this->assertFalse($this->instance->exists('foo'));
  46. }
  47. public function testArrayInterface() {
  48. $this->assertFalse(isset($this->instance['foo']));
  49. $this->instance['foo'] = 'bar';
  50. $this->assertTrue(isset($this->instance['foo']));
  51. $this->assertEquals('bar', $this->instance['foo']);
  52. unset($this->instance['foo']);
  53. $this->assertFalse(isset($this->instance['foo']));
  54. }
  55. }