/Tests/Unit/Session/TransientSessionTest.php

https://github.com/arbyte/FLOW3-X-TYPO3.FLOW3 · PHP · 80 lines · 38 code · 10 blank · 32 comment · 1 complexity · 0208b709fce5a8c0e50b101a50e28f3c MD5 · raw file

  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Session;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * Testcase for the Transient Session implementation
  14. *
  15. */
  16. class TransientSessionTest extends \TYPO3\FLOW3\Tests\UnitTestCase {
  17. /**
  18. * @test
  19. */
  20. public function theTransientSessionImplementsTheSessionInterface() {
  21. $session = new \TYPO3\FLOW3\Session\TransientSession();
  22. $this->assertInstanceOf('TYPO3\FLOW3\Session\SessionInterface', $session);
  23. }
  24. /**
  25. * @test
  26. */
  27. public function aSessionIdIsGeneratedOnStartingTheSession() {
  28. $session = new \TYPO3\FLOW3\Session\TransientSession();
  29. $session->start();
  30. $this->assertTrue(strlen($session->getId()) == 13);
  31. }
  32. /**
  33. * @test
  34. * @expectedException \TYPO3\FLOW3\Session\Exception\SessionNotStartedException
  35. */
  36. public function tryingToGetTheSessionIdWithoutStartingTheSessionThrowsAnException() {
  37. $session = new \TYPO3\FLOW3\Session\TransientSession();
  38. $session->getId();
  39. }
  40. /**
  41. * @test
  42. */
  43. public function stringsCanBeStoredByCallingPutData() {
  44. $session = new \TYPO3\FLOW3\Session\TransientSession();
  45. $session->start();
  46. $session->putData('theKey', 'some data');
  47. $this->assertEquals('some data', $session->getData('theKey'));
  48. }
  49. /**
  50. * @test
  51. */
  52. public function allSessionDataCanBeFlushedByCallingDestroy() {
  53. $session = new \TYPO3\FLOW3\Session\TransientSession();
  54. $session->start();
  55. $session->putData('theKey', 'some data');
  56. $session->destroy();
  57. $this->assertNull($session->getData('theKey'));
  58. }
  59. /**
  60. * @test
  61. */
  62. public function hasKeyReturnsTrueOrFalseAccordingToAvailableKeys() {
  63. $session = new \TYPO3\FLOW3\Session\TransientSession();
  64. $session->start();
  65. $session->putData('theKey', 'some data');
  66. $this->assertTrue($session->hasKey('theKey'));
  67. $this->assertFalse($session->hasKey('noKey'));
  68. }
  69. }
  70. ?>