2010-07-25 20:40:44 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CacheSessionTest
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-25 20:40:44 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-07-25 20:40:44 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-25 20:40:44 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Datasource.Session
|
2010-07-25 20:40:44 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-07-25 20:40:44 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('CakeSession', 'Model/Datasource');
|
|
|
|
App::uses('CacheSession', 'Model/Datasource/Session');
|
2010-12-22 03:02:49 +00:00
|
|
|
class_exists('CakeSession');
|
2010-07-25 20:40:44 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
|
|
|
* Class CacheSessionTest
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model.Datasource.Session
|
|
|
|
*/
|
2010-07-25 20:40:44 +00:00
|
|
|
class CacheSessionTest extends CakeTestCase {
|
|
|
|
|
|
|
|
protected static $_sessionBackup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test case startup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function setupBeforeClass() {
|
|
|
|
Cache::config('session_test', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'prefix' => 'session_test_'
|
|
|
|
));
|
2015-07-21 08:22:53 +00:00
|
|
|
static::$_sessionBackup = Configure::read('Session');
|
2010-07-25 21:06:03 +00:00
|
|
|
|
|
|
|
Configure::write('Session.handler.config', 'session_test');
|
2010-07-25 20:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cleanup after test case.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function teardownAfterClass() {
|
2012-02-10 19:38:41 +00:00
|
|
|
Cache::clear(false, 'session_test');
|
2010-07-25 20:40:44 +00:00
|
|
|
Cache::drop('session_test');
|
|
|
|
|
2015-07-21 08:22:53 +00:00
|
|
|
Configure::write('Session', static::$_sessionBackup);
|
2010-07-25 20:40:44 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 04:43:58 +00:00
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-28 04:11:11 +00:00
|
|
|
parent::setUp();
|
2010-09-06 04:43:58 +00:00
|
|
|
$this->storage = new CacheSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2010-09-06 04:43:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2010-09-06 04:43:58 +00:00
|
|
|
unset($this->storage);
|
|
|
|
}
|
|
|
|
|
2010-07-25 20:40:44 +00:00
|
|
|
/**
|
|
|
|
* test open
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOpen() {
|
2010-09-06 04:43:58 +00:00
|
|
|
$this->assertTrue($this->storage->open());
|
2010-07-25 20:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test write()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWrite() {
|
2010-09-06 04:43:58 +00:00
|
|
|
$this->storage->write('abc', 'Some value');
|
2010-07-25 20:40:44 +00:00
|
|
|
$this->assertEquals('Some value', Cache::read('abc', 'session_test'), 'Value was not written.');
|
|
|
|
$this->assertFalse(Cache::read('abc', 'default'), 'Cache should only write to the given config.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test reading.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRead() {
|
2010-09-06 04:43:58 +00:00
|
|
|
$this->storage->write('test_one', 'Some other value');
|
|
|
|
$this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
|
2015-12-29 04:26:06 +00:00
|
|
|
$this->storage->write('test_two', 0);
|
|
|
|
$this->assertEquals(0, $this->storage->read('test_two'));
|
2010-07-25 20:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test destroy
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDestroy() {
|
2010-09-06 04:43:58 +00:00
|
|
|
$this->storage->write('test_one', 'Some other value');
|
|
|
|
$this->assertTrue($this->storage->destroy('test_one'), 'Value was not deleted.');
|
2010-07-25 20:40:44 +00:00
|
|
|
|
|
|
|
$this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
|
|
|
|
}
|
|
|
|
|
2012-12-05 14:00:24 +00:00
|
|
|
}
|