CacheSessionTest.php 2.7 KB

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