CacheSessionTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * CacheSessionTest
  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://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. * Class CacheSessionTest
  25. *
  26. */
  27. class CacheSessionTest extends TestCase {
  28. protected static $_sessionBackup;
  29. /**
  30. * setup
  31. *
  32. * @return void
  33. */
  34. public function setUp() {
  35. parent::setUp();
  36. Cache::config(['session_test' => ['engine' => 'File']]);
  37. $this->storage = new CacheSession(['config' => 'session_test']);
  38. }
  39. /**
  40. * tearDown
  41. *
  42. * @return void
  43. */
  44. public function tearDown() {
  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. $this->assertTrue($this->storage->open(null, null));
  57. }
  58. /**
  59. * test write()
  60. *
  61. * @return void
  62. */
  63. public function testWrite() {
  64. $this->storage->write('abc', 'Some value');
  65. $this->assertEquals('Some value', Cache::read('abc', 'session_test'), 'Value was not written.');
  66. }
  67. /**
  68. * test reading.
  69. *
  70. * @return void
  71. */
  72. public function testRead() {
  73. $this->storage->write('test_one', 'Some other value');
  74. $this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
  75. }
  76. /**
  77. * test destroy
  78. *
  79. * @return void
  80. */
  81. public function testDestroy() {
  82. $this->storage->write('test_one', 'Some other value');
  83. $this->assertTrue($this->storage->destroy('test_one'), 'Value was not deleted.');
  84. $this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
  85. }
  86. /**
  87. * Tests that a cache config is required
  88. *
  89. * @expectedException InvalidArgumentException
  90. * @expectedExceptionMessage The cache configuration name to use is required
  91. * @return void
  92. */
  93. public function testMissingConfig() {
  94. new CacheSession(['foo' => 'bar']);
  95. }
  96. }