SessionStorageTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 2.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Auth;
  16. use Cake\Auth\Storage\SessionStorage;
  17. use Cake\Network\Request;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for SessionStorage
  21. *
  22. */
  23. class SessionStorageTest extends TestCase
  24. {
  25. /**
  26. * setup
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. $this->session = $this->getMock('Cake\Network\Session');
  34. $this->request = new Request(['session' => $this->session]);
  35. $this->storage = new SessionStorage($this->request, ['key' => 'Auth.AuthUser']);
  36. $this->user = ['id' => 1];
  37. }
  38. /**
  39. * Test set
  40. *
  41. * @return void
  42. */
  43. public function testSet()
  44. {
  45. $this->session->expects($this->once())
  46. ->method('write')
  47. ->with('Auth.AuthUser', $this->user)
  48. ->will($this->returnValue(true));
  49. $this->storage->set($this->user);
  50. }
  51. /**
  52. * Test get
  53. *
  54. * @return void
  55. */
  56. public function testGet()
  57. {
  58. $this->session->expects($this->once())
  59. ->method('check')
  60. ->with('Auth.AuthUser')
  61. ->will($this->returnValue(true));
  62. $this->session->expects($this->once())
  63. ->method('read')
  64. ->with('Auth.AuthUser')
  65. ->will($this->returnValue($this->user));
  66. $result = $this->storage->get();
  67. $this->assertSame($this->user, $result);
  68. }
  69. /**
  70. * Test remove
  71. *
  72. * @return void
  73. */
  74. public function testRemove()
  75. {
  76. $this->session->expects($this->once())
  77. ->method('delete')
  78. ->with('Auth.AuthUser');
  79. $this->storage->remove();
  80. }
  81. }