Skip to content

Commit

Permalink
Updating CakeSession test case and fixing a few issues in the default…
Browse files Browse the repository at this point in the history
… settings.
  • Loading branch information
markstory committed Jul 28, 2010
1 parent b247559 commit 339fa29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 94 deletions.
92 changes: 12 additions & 80 deletions cake/libs/cake_session.php
Expand Up @@ -191,7 +191,7 @@ protected static function _setHost($host) {
* @return void
*/
protected function _setupDatabase() {
if (Configure::read('Session.save') !== 'database') {
if (Configure::read('Session.defaults') !== 'database') {
return;
}
$modelName = Configure::read('Session.model');
Expand Down Expand Up @@ -227,7 +227,7 @@ public static function start() {
}

session_write_close();
self::__initSession();
self::_configureSession();
self::_startSession();
$started = self::started();

Expand Down Expand Up @@ -484,7 +484,7 @@ public static function write($name, $value = null) {
* @return void
*/
public static function destroy() {
$_SESSION = null;
$_SESSION = array();
self::$id = null;
self::init(self::$path);
self::start();
Expand All @@ -510,9 +510,10 @@ public static function destroy() {
* to the ini array.
* - `Session.ini` - An associative array of additional ini values to set.
*
* @access private
* @return void
* @throws Exception Throws exceptions when ini_set() fails.
*/
function __initSession() {
protected static function _configureSession() {
$sessionConfig = Configure::read('Session');
$iniSet = function_exists('ini_set');

Expand All @@ -535,7 +536,7 @@ function __initSession() {
$sessionConfig['ini']['session.name'] = $sessionConfig['cookie'];
}
if (!empty($sessionConfig['handler'])) {
$sessionConfig['ini']['sesssion.save_handler'] = 'user';
$sessionConfig['ini']['session.save_handler'] = 'user';
}

if (empty($_SESSION)) {
Expand All @@ -553,78 +554,6 @@ function __initSession() {

/*
switch (Configure::read('Session.save')) {
case 'cake':
if (empty($_SESSION) && $iniSet) {
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
ini_set('session.serialize_handler', 'php');
ini_set('session.use_cookies', 1);
ini_set('session.name', Configure::read('Session.cookie'));
ini_set('session.cookie_lifetime', self::$cookieLifeTime);
ini_set('session.cookie_path', self::$path);
ini_set('session.auto_start', 0);
ini_set('session.save_path', TMP . 'sessions');
}
break;
case 'database':
if (empty($_SESSION)) {
if (Configure::read('Session.model') === null) {
trigger_error(__("You must set the all Configure::write('Session.*') in core.php to use database storage"), E_USER_WARNING);
self::_stop();
}
if ($iniSet) {
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
ini_set('session.save_handler', 'user');
ini_set('session.serialize_handler', 'php');
ini_set('session.use_cookies', 1);
ini_set('session.name', Configure::read('Session.cookie'));
ini_set('session.cookie_lifetime', self::$cookieLifeTime);
ini_set('session.cookie_path', self::$path);
ini_set('session.auto_start', 0);
}
}
session_set_save_handler(
array('CakeSession','__open'),
array('CakeSession', '__close'),
array('CakeSession', '__read'),
array('CakeSession', '__write'),
array('CakeSession', '__destroy'),
array('CakeSession', '__gc')
);
break;
case 'php':
if (empty($_SESSION) && $iniSet) {
ini_set('session.use_trans_sid', 0);
ini_set('session.name', Configure::read('Session.cookie'));
ini_set('session.cookie_lifetime', self::$cookieLifeTime);
ini_set('session.cookie_path', self::$path);
}
break;
case 'cache':
if (empty($_SESSION)) {
if (!class_exists('Cache')) {
require LIBS . 'cache.php';
}
if ($iniSet) {
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
ini_set('session.save_handler', 'user');
ini_set('session.use_cookies', 1);
ini_set('session.name', Configure::read('Session.cookie'));
ini_set('session.cookie_lifetime', self::$cookieLifeTime);
ini_set('session.cookie_path', self::$path);
}
}
session_set_save_handler(
array('CakeSession','__open'),
array('CakeSession', '__close'),
array('Cache', 'read'),
array('Cache', 'write'),
array('Cache', 'delete'),
array('Cache', 'gc')
);
break;
default:
$config = CONFIGS . Configure::read('Session.save') . '.php';
Expand All @@ -649,7 +578,8 @@ protected static function _defaultConfig($name) {
'cookieTimeout' => 240,
'ini' => array(
'session.use_trans_sid' => 0,
'session.cookie_path' => self::$path
'session.cookie_path' => self::$path,
'session.save_handler' => 'files'
)
),
'cake' => array(
Expand All @@ -663,7 +593,8 @@ protected static function _defaultConfig($name) {
'session.use_cookies' => 1,
'session.cookie_path' => self::$path,
'session.auto_start' => 0,
'session.save_path' => TMP . 'sessions'
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
)
),
'cache' => array(
Expand All @@ -673,6 +604,7 @@ protected static function _defaultConfig($name) {
'ini' => array(
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.auto_start' => 0,
'session.use_cookies' => 1,
'session.cookie_path' => self::$path,
'session.save_handler' => 'user',
Expand Down
26 changes: 12 additions & 14 deletions cake/tests/cases/libs/cake_session.test.php
Expand Up @@ -85,7 +85,6 @@ function startTest() {
'timeout' => 120,
'cookieTimeout' => 120,
'ini' => array(),
'handler' => null
));

TestCakeSession::init();
Expand Down Expand Up @@ -506,9 +505,10 @@ function testCheckUserAgentTrue() {
*/
function testReadAndWriteWithCakeStorage() {
session_write_close();
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'cake');
$this->setUp();
Configure::write('Session.defaults', 'cake');

TestCakeSession::init();
TestCakeSession::destroy();

TestCakeSession::write('SessionTestCase', 0);
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
Expand Down Expand Up @@ -542,9 +542,10 @@ function testReadAndWriteWithCakeStorage() {
*/
function testReadAndWriteWithCacheStorage() {
session_write_close();
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'cache');
$this->setUp();
Configure::write('Session.defaults', 'cache');

TestCakeSession::init();
TestCakeSession::destroy();

TestCakeSession::write('SessionTestCase', 0);
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
Expand Down Expand Up @@ -580,8 +581,10 @@ function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.table', 'sessions');
Configure::write('Session.model', 'Session');
Configure::write('Session.database', 'test_suite');
Configure::write('Session.save', 'database');
$this->startTest();
Configure::write('Session.defaults', 'database');

TestCakeSession::init();
TestCakeSession::destroy();

TestCakeSession::write('SessionTestCase', 0);
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
Expand All @@ -605,11 +608,6 @@ function testReadAndWriteWithDatabaseStorage() {
TestCakeSession::destroy();
$this->assertNull(TestCakeSession::read('SessionTestCase'));
session_write_close();

unset($_SESSION);
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'php');
$this->startTest();
}

}

0 comments on commit 339fa29

Please sign in to comment.