MemoryStorageTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : 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(tm) Project
  13. * @since 3.2.12
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Auth\Storage;
  17. use Cake\Auth\Storage\MemoryStorage;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for MemoryStorage
  21. */
  22. class MemoryStorageTest extends TestCase
  23. {
  24. /**
  25. * @var \Cake\Auth\Storage\MemoryStorage
  26. */
  27. protected $storage;
  28. /**
  29. * @var array
  30. */
  31. protected $user;
  32. /**
  33. * Setup
  34. */
  35. public function setUp(): void
  36. {
  37. parent::setUp();
  38. $this->storage = new MemoryStorage();
  39. $this->user = ['username' => 'giantGummyLizard'];
  40. }
  41. /**
  42. * Test write.
  43. */
  44. public function testWrite(): void
  45. {
  46. $this->storage->write($this->user);
  47. $this->assertSame($this->user, $this->storage->read());
  48. }
  49. /**
  50. * Test read.
  51. */
  52. public function testRead(): void
  53. {
  54. $this->assertNull($this->storage->read());
  55. }
  56. /**
  57. * Test delete.
  58. */
  59. public function testDelete(): void
  60. {
  61. $this->storage->write($this->user);
  62. $this->storage->delete();
  63. $this->assertNull($this->storage->read());
  64. }
  65. /**
  66. * Test redirectUrl.
  67. */
  68. public function testRedirectUrl(): void
  69. {
  70. $this->assertNull($this->storage->redirectUrl());
  71. $this->storage->redirectUrl('/posts/the-gummy-lizards');
  72. $this->assertSame('/posts/the-gummy-lizards', $this->storage->redirectUrl());
  73. $this->assertNull($this->storage->redirectUrl(false));
  74. $this->assertNull($this->storage->redirectUrl());
  75. }
  76. }