2010-07-25 20:40:44 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CacheSessionTest
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-25 20:40:44 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-25 20:40:44 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.session
|
2010-07-25 20:40:44 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
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_'
|
|
|
|
));
|
|
|
|
self::$_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() {
|
|
|
|
Cache::clear('session_test');
|
|
|
|
Cache::drop('session_test');
|
|
|
|
|
|
|
|
Configure::write('Session', self::$_sessionBackup);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* teardown
|
|
|
|
*
|
|
|
|
* @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.');
|
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.');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|