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