TestSessionTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP Project
  13. * @since 4.0.5
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\TestSuite;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\TestSuite\TestSession;
  19. class TestSessionTest extends TestCase
  20. {
  21. /**
  22. * @var array
  23. */
  24. protected $sessionData;
  25. /**
  26. * @var \Cake\TestSuite\TestSession
  27. */
  28. protected $session;
  29. public function setUp(): void
  30. {
  31. parent::setUp();
  32. $this->sessionData = [
  33. 'root' => [
  34. 'sub' => [
  35. 'subsub' => 'foo',
  36. ],
  37. ],
  38. ];
  39. $this->session = new TestSession($this->sessionData);
  40. }
  41. /**
  42. * Tests read()
  43. */
  44. public function testRead(): void
  45. {
  46. $result = $this->session->read();
  47. $this->assertSame($this->sessionData, $result);
  48. $result = $this->session->read('root.sub');
  49. $this->assertSame(['subsub' => 'foo'], $result);
  50. }
  51. /**
  52. * Tests check()
  53. */
  54. public function testCheck(): void
  55. {
  56. $result = $this->session->check();
  57. $this->assertTrue($result);
  58. $result = $this->session->check('root.sub');
  59. $this->assertTrue($result);
  60. $result = $this->session->check('root.nonexistent');
  61. $this->assertFalse($result);
  62. }
  63. }