mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fix clear(). Add test cases.
This commit is contained in:
parent
35e0dc2bbd
commit
611889235a
2 changed files with 16 additions and 5 deletions
|
@ -374,7 +374,7 @@ class CakeSession {
|
||||||
*
|
*
|
||||||
* @param string|null $name The name of the session variable (or a path as sent to Set.extract)
|
* @param string|null $name The name of the session variable (or a path as sent to Set.extract)
|
||||||
* @return mixed The value of the session variable, null if session not available,
|
* @return mixed The value of the session variable, null if session not available,
|
||||||
* session not started, or provided name not found in the session.
|
* session not started, or provided name not found in the session, false on failure.
|
||||||
*/
|
*/
|
||||||
public static function read($name = null) {
|
public static function read($name = null) {
|
||||||
if (empty($name) && $name !== null) {
|
if (empty($name) && $name !== null) {
|
||||||
|
@ -478,12 +478,15 @@ class CakeSession {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function clear($renew = true) {
|
public static function clear($renew = true) {
|
||||||
|
if (!$renew) {
|
||||||
|
$_SESSION = array();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$_SESSION = null;
|
$_SESSION = null;
|
||||||
if ($renew) {
|
|
||||||
self::$id = null;
|
self::$id = null;
|
||||||
self::renew();
|
self::renew();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to initialize a session, based on CakePHP core settings.
|
* Helper method to initialize a session, based on CakePHP core settings.
|
||||||
|
|
|
@ -413,6 +413,14 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
TestCakeSession::clear(false);
|
TestCakeSession::clear(false);
|
||||||
$this->assertFalse(TestCakeSession::check('Delete.me'));
|
$this->assertFalse(TestCakeSession::check('Delete.me'));
|
||||||
$this->assertFalse(TestCakeSession::check('Delete'));
|
$this->assertFalse(TestCakeSession::check('Delete'));
|
||||||
|
|
||||||
|
TestCakeSession::write('Some.string', 'value');
|
||||||
|
TestCakeSession::clear(false);
|
||||||
|
$this->assertNull(TestCakeSession::read('Some'));
|
||||||
|
|
||||||
|
TestCakeSession::write('Some.string.array', array('values'));
|
||||||
|
TestCakeSession::clear(false);
|
||||||
|
$this->assertFalse(TestCakeSession::read());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue