CacheSessionTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * CacheSessionTest
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  13. * @link https://cakephp.org CakePHP(tm) Project
  14. * @since 2.0.0
  15. * @license https://opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Network\Session;
  18. use Cake\Cache\Cache;
  19. use Cake\Network\Session\CacheSession;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * CacheSessionTest
  23. */
  24. class CacheSessionTest extends TestCase
  25. {
  26. protected static $_sessionBackup;
  27. /**
  28. * setup
  29. *
  30. * @return void
  31. */
  32. public function setUp()
  33. {
  34. parent::setUp();
  35. Cache::config(['session_test' => ['engine' => 'File']]);
  36. $this->storage = new CacheSession(['config' => 'session_test']);
  37. }
  38. /**
  39. * tearDown
  40. *
  41. * @return void
  42. */
  43. public function tearDown()
  44. {
  45. parent::tearDown();
  46. Cache::clear(false, 'session_test');
  47. Cache::drop('session_test');
  48. unset($this->storage);
  49. }
  50. /**
  51. * test open
  52. *
  53. * @return void
  54. */
  55. public function testOpen()
  56. {
  57. $this->assertTrue($this->storage->open(null, null));
  58. }
  59. /**
  60. * test write()
  61. *
  62. * @return void
  63. */
  64. public function testWrite()
  65. {
  66. $this->storage->write('abc', 'Some value');
  67. $this->assertEquals('Some value', Cache::read('abc', 'session_test'), 'Value was not written.');
  68. }
  69. /**
  70. * test reading.
  71. *
  72. * @return void
  73. */
  74. public function testRead()
  75. {
  76. $this->storage->write('test_one', 'Some other value');
  77. $this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
  78. }
  79. /**
  80. * test destroy
  81. *
  82. * @return void
  83. */
  84. public function testDestroy()
  85. {
  86. $this->storage->write('test_one', 'Some other value');
  87. $this->assertTrue($this->storage->destroy('test_one'), 'Value was not deleted.');
  88. $this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
  89. }
  90. /**
  91. * Tests that a cache config is required
  92. *
  93. * @expectedException \InvalidArgumentException
  94. * @expectedExceptionMessage The cache configuration name to use is required
  95. * @return void
  96. */
  97. public function testMissingConfig()
  98. {
  99. new CacheSession(['foo' => 'bar']);
  100. }
  101. }