mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating CakeSession test case and fixing a few issues in the default settings.
This commit is contained in:
parent
b247559e9e
commit
339fa29502
2 changed files with 24 additions and 94 deletions
|
@ -191,7 +191,7 @@ class CakeSession {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _setupDatabase() {
|
protected function _setupDatabase() {
|
||||||
if (Configure::read('Session.save') !== 'database') {
|
if (Configure::read('Session.defaults') !== 'database') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$modelName = Configure::read('Session.model');
|
$modelName = Configure::read('Session.model');
|
||||||
|
@ -227,7 +227,7 @@ class CakeSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
session_write_close();
|
session_write_close();
|
||||||
self::__initSession();
|
self::_configureSession();
|
||||||
self::_startSession();
|
self::_startSession();
|
||||||
$started = self::started();
|
$started = self::started();
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ class CakeSession {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function destroy() {
|
public static function destroy() {
|
||||||
$_SESSION = null;
|
$_SESSION = array();
|
||||||
self::$id = null;
|
self::$id = null;
|
||||||
self::init(self::$path);
|
self::init(self::$path);
|
||||||
self::start();
|
self::start();
|
||||||
|
@ -510,9 +510,10 @@ class CakeSession {
|
||||||
* to the ini array.
|
* to the ini array.
|
||||||
* - `Session.ini` - An associative array of additional ini values to set.
|
* - `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');
|
$sessionConfig = Configure::read('Session');
|
||||||
$iniSet = function_exists('ini_set');
|
$iniSet = function_exists('ini_set');
|
||||||
|
|
||||||
|
@ -535,7 +536,7 @@ class CakeSession {
|
||||||
$sessionConfig['ini']['session.name'] = $sessionConfig['cookie'];
|
$sessionConfig['ini']['session.name'] = $sessionConfig['cookie'];
|
||||||
}
|
}
|
||||||
if (!empty($sessionConfig['handler'])) {
|
if (!empty($sessionConfig['handler'])) {
|
||||||
$sessionConfig['ini']['sesssion.save_handler'] = 'user';
|
$sessionConfig['ini']['session.save_handler'] = 'user';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($_SESSION)) {
|
if (empty($_SESSION)) {
|
||||||
|
@ -553,78 +554,6 @@ class CakeSession {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
switch (Configure::read('Session.save')) {
|
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:
|
default:
|
||||||
$config = CONFIGS . Configure::read('Session.save') . '.php';
|
$config = CONFIGS . Configure::read('Session.save') . '.php';
|
||||||
|
|
||||||
|
@ -649,7 +578,8 @@ class CakeSession {
|
||||||
'cookieTimeout' => 240,
|
'cookieTimeout' => 240,
|
||||||
'ini' => array(
|
'ini' => array(
|
||||||
'session.use_trans_sid' => 0,
|
'session.use_trans_sid' => 0,
|
||||||
'session.cookie_path' => self::$path
|
'session.cookie_path' => self::$path,
|
||||||
|
'session.save_handler' => 'files'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'cake' => array(
|
'cake' => array(
|
||||||
|
@ -663,7 +593,8 @@ class CakeSession {
|
||||||
'session.use_cookies' => 1,
|
'session.use_cookies' => 1,
|
||||||
'session.cookie_path' => self::$path,
|
'session.cookie_path' => self::$path,
|
||||||
'session.auto_start' => 0,
|
'session.auto_start' => 0,
|
||||||
'session.save_path' => TMP . 'sessions'
|
'session.save_path' => TMP . 'sessions',
|
||||||
|
'session.save_handler' => 'files'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'cache' => array(
|
'cache' => array(
|
||||||
|
@ -673,6 +604,7 @@ class CakeSession {
|
||||||
'ini' => array(
|
'ini' => array(
|
||||||
'session.use_trans_sid' => 0,
|
'session.use_trans_sid' => 0,
|
||||||
'url_rewriter.tags' => '',
|
'url_rewriter.tags' => '',
|
||||||
|
'session.auto_start' => 0,
|
||||||
'session.use_cookies' => 1,
|
'session.use_cookies' => 1,
|
||||||
'session.cookie_path' => self::$path,
|
'session.cookie_path' => self::$path,
|
||||||
'session.save_handler' => 'user',
|
'session.save_handler' => 'user',
|
||||||
|
|
|
@ -85,7 +85,6 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
'timeout' => 120,
|
'timeout' => 120,
|
||||||
'cookieTimeout' => 120,
|
'cookieTimeout' => 120,
|
||||||
'ini' => array(),
|
'ini' => array(),
|
||||||
'handler' => null
|
|
||||||
));
|
));
|
||||||
|
|
||||||
TestCakeSession::init();
|
TestCakeSession::init();
|
||||||
|
@ -506,9 +505,10 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testReadAndWriteWithCakeStorage() {
|
function testReadAndWriteWithCakeStorage() {
|
||||||
session_write_close();
|
session_write_close();
|
||||||
ini_set('session.save_handler', 'files');
|
Configure::write('Session.defaults', 'cake');
|
||||||
Configure::write('Session.save', 'cake');
|
|
||||||
$this->setUp();
|
TestCakeSession::init();
|
||||||
|
TestCakeSession::destroy();
|
||||||
|
|
||||||
TestCakeSession::write('SessionTestCase', 0);
|
TestCakeSession::write('SessionTestCase', 0);
|
||||||
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
||||||
|
@ -542,9 +542,10 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testReadAndWriteWithCacheStorage() {
|
function testReadAndWriteWithCacheStorage() {
|
||||||
session_write_close();
|
session_write_close();
|
||||||
ini_set('session.save_handler', 'files');
|
Configure::write('Session.defaults', 'cache');
|
||||||
Configure::write('Session.save', 'cache');
|
|
||||||
$this->setUp();
|
TestCakeSession::init();
|
||||||
|
TestCakeSession::destroy();
|
||||||
|
|
||||||
TestCakeSession::write('SessionTestCase', 0);
|
TestCakeSession::write('SessionTestCase', 0);
|
||||||
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
||||||
|
@ -580,8 +581,10 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
Configure::write('Session.table', 'sessions');
|
Configure::write('Session.table', 'sessions');
|
||||||
Configure::write('Session.model', 'Session');
|
Configure::write('Session.model', 'Session');
|
||||||
Configure::write('Session.database', 'test_suite');
|
Configure::write('Session.database', 'test_suite');
|
||||||
Configure::write('Session.save', 'database');
|
Configure::write('Session.defaults', 'database');
|
||||||
$this->startTest();
|
|
||||||
|
TestCakeSession::init();
|
||||||
|
TestCakeSession::destroy();
|
||||||
|
|
||||||
TestCakeSession::write('SessionTestCase', 0);
|
TestCakeSession::write('SessionTestCase', 0);
|
||||||
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
$this->assertEqual(TestCakeSession::read('SessionTestCase'), 0);
|
||||||
|
@ -605,11 +608,6 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
TestCakeSession::destroy();
|
TestCakeSession::destroy();
|
||||||
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
||||||
session_write_close();
|
session_write_close();
|
||||||
|
|
||||||
unset($_SESSION);
|
|
||||||
ini_set('session.save_handler', 'files');
|
|
||||||
Configure::write('Session.save', 'php');
|
|
||||||
$this->startTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue