SessionHelperTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * SessionHelperTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @since 1.2.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\View\Helper;
  18. use Cake\Controller\Controller;
  19. use Cake\Core\App;
  20. use Cake\Core\Plugin;
  21. use Cake\Network\Request;
  22. use Cake\Network\Session;
  23. use Cake\TestSuite\TestCase;
  24. use Cake\View\Helper\SessionHelper;
  25. use Cake\View\View;
  26. /**
  27. * SessionHelperTest class
  28. *
  29. */
  30. class SessionHelperTest extends TestCase
  31. {
  32. /**
  33. * setUp method
  34. *
  35. * @return void
  36. */
  37. public function setUp()
  38. {
  39. parent::setUp();
  40. $this->View = new View();
  41. $session = new Session();
  42. $this->View->request = new Request(['session' => $session]);
  43. $this->Session = new SessionHelper($this->View);
  44. $session->write([
  45. 'test' => 'info',
  46. 'Flash' => [
  47. 'flash' => [
  48. 'type' => 'info',
  49. 'params' => [],
  50. 'message' => 'This is a calling'
  51. ],
  52. 'notification' => [
  53. 'type' => 'info',
  54. 'params' => [
  55. 'title' => 'Notice!',
  56. 'name' => 'Alert!',
  57. 'element' => 'session_helper'
  58. ],
  59. 'message' => 'This is a test of the emergency broadcasting system',
  60. ],
  61. 'classy' => [
  62. 'type' => 'success',
  63. 'params' => ['class' => 'positive'],
  64. 'message' => 'Recorded'
  65. ],
  66. 'incomplete' => [
  67. 'message' => 'A thing happened',
  68. ]
  69. ],
  70. 'Deeply' => ['nested' => ['key' => 'value']],
  71. ]);
  72. }
  73. /**
  74. * tearDown method
  75. *
  76. * @return void
  77. */
  78. public function tearDown()
  79. {
  80. $_SESSION = [];
  81. unset($this->View, $this->Session);
  82. Plugin::unload();
  83. parent::tearDown();
  84. }
  85. /**
  86. * testRead method
  87. *
  88. * @return void
  89. */
  90. public function testRead()
  91. {
  92. $result = $this->Session->read('Deeply.nested.key');
  93. $this->assertEquals('value', $result);
  94. $result = $this->Session->read('test');
  95. $this->assertEquals('info', $result);
  96. }
  97. /**
  98. * testCheck method
  99. *
  100. * @return void
  101. */
  102. public function testCheck()
  103. {
  104. $this->assertTrue($this->Session->check('test'));
  105. $this->assertTrue($this->Session->check('Flash.flash'));
  106. $this->assertFalse($this->Session->check('Does.not.exist'));
  107. $this->assertFalse($this->Session->check('Nope'));
  108. }
  109. }