1
0

Session.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Session;
  8. abstract class Session extends \Test\TestCase {
  9. /**
  10. * @var \OC\Session\Session
  11. */
  12. protected $instance;
  13. protected function tearDown(): void {
  14. $this->instance->clear();
  15. parent::tearDown();
  16. }
  17. public function testNotExistsEmpty(): void {
  18. $this->assertFalse($this->instance->exists('foo'));
  19. }
  20. public function testExistsAfterSet(): void {
  21. $this->instance->set('foo', 1);
  22. $this->assertTrue($this->instance->exists('foo'));
  23. }
  24. public function testNotExistsAfterRemove(): void {
  25. $this->instance->set('foo', 1);
  26. $this->instance->remove('foo');
  27. $this->assertFalse($this->instance->exists('foo'));
  28. }
  29. public function testGetNonExisting(): void {
  30. $this->assertNull($this->instance->get('foo'));
  31. }
  32. public function testGetAfterSet(): void {
  33. $this->instance->set('foo', 'bar');
  34. $this->assertEquals('bar', $this->instance->get(('foo')));
  35. }
  36. public function testRemoveNonExisting(): void {
  37. $this->assertFalse($this->instance->exists('foo'));
  38. $this->instance->remove('foo');
  39. $this->assertFalse($this->instance->exists('foo'));
  40. }
  41. public function testNotExistsAfterClear(): void {
  42. $this->instance->set('foo', 1);
  43. $this->instance->clear();
  44. $this->assertFalse($this->instance->exists('foo'));
  45. }
  46. public function testArrayInterface(): void {
  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. }