CacheSessionTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. {
  29. protected static $_sessionBackup;
  30. /**
  31. * setup
  32. *
  33. * @return void
  34. */
  35. public function setUp()
  36. {
  37. parent::setUp();
  38. Cache::config(['session_test' => ['engine' => 'File']]);
  39. $this->storage = new CacheSession(['config' => 'session_test']);
  40. }
  41. /**
  42. * tearDown
  43. *
  44. * @return void
  45. */
  46. public function tearDown()
  47. {
  48. parent::tearDown();
  49. Cache::clear(false, 'session_test');
  50. Cache::drop('session_test');
  51. unset($this->storage);
  52. }
  53. /**
  54. * test open
  55. *
  56. * @return void
  57. */
  58. public function testOpen()
  59. {
  60. $this->assertTrue($this->storage->open(null, null));
  61. }
  62. /**
  63. * test write()
  64. *
  65. * @return void
  66. */
  67. public function testWrite()
  68. {
  69. $this->storage->write('abc', 'Some value');
  70. $this->assertEquals('Some value', Cache::read('abc', 'session_test'), 'Value was not written.');
  71. }
  72. /**
  73. * test reading.
  74. *
  75. * @return void
  76. */
  77. public function testRead()
  78. {
  79. $this->storage->write('test_one', 'Some other value');
  80. $this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
  81. }
  82. /**
  83. * test destroy
  84. *
  85. * @return void
  86. */
  87. public function testDestroy()
  88. {
  89. $this->storage->write('test_one', 'Some other value');
  90. $this->assertTrue($this->storage->destroy('test_one'), 'Value was not deleted.');
  91. $this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
  92. }
  93. /**
  94. * Tests that a cache config is required
  95. *
  96. * @expectedException \InvalidArgumentException
  97. * @expectedExceptionMessage The cache configuration name to use is required
  98. * @return void
  99. */
  100. public function testMissingConfig()
  101. {
  102. new CacheSession(['foo' => 'bar']);
  103. }
  104. }