Add test for path containing question, and fix assignment of CakeSession::path

This commit is contained in:
predominant 2010-07-22 18:42:56 +10:00 committed by mark_story
parent f5565895e9
commit a63474a54d
2 changed files with 33 additions and 24 deletions

View file

@ -144,6 +144,7 @@ class CakeSession {
if ($start === true) {
self::_setPath($base);
self::_setHost();
self::start();
}
if (isset($_SESSION) || $start === true) {
self::$sessionTime = self::$time + (Security::inactiveMins() * Configure::read('Session.timeout'));
@ -162,14 +163,13 @@ class CakeSession {
self::$path = '/';
return;
}
self::$path = $base;
if (strpos($base, 'index.php') !== false) {
self::$path = str_replace('index.php', '', $base);
$base = str_replace('index.php', '', $base);
}
if (strpos($base, '?') !== false) {
self::$path = str_replace('?', '', $base);
$base = str_replace('?', '', $base);
}
self::$path = $base;
}
/**
@ -222,28 +222,19 @@ class CakeSession {
* @return boolean True if session was started
*/
public static function start() {
if (!self::started()) {
session_write_close();
self::__initSession();
self::_startSession();
if (self::started()) {
return true;
}
return self::started();
}
/**
* Begins the session if it hasn't already been started, and runs _checkValid which sets up some
* session tampering settings.
*
* @return void
*/
public static function begin() {
if (self::started() === false) {
if (!self::id() && self::start()) {
self::_checkValid();
} else {
self::start();
}
session_write_close();
self::__initSession();
self::_startSession();
$started = self::started();
if (!self::id() && $started) {
self::_checkValid();
}
self::$error = array();
return self::started();
}

View file

@ -96,17 +96,35 @@ class CakeSessionTest extends CakeTestCase {
* @return void
*/
function testSessionPath() {
// $Session = new CakeSession('/index.php');
TestCakeSession::init('/index.php');
$this->assertEqual('/', TestCakeSession::$path);
TestCakeSession::init('/sub_dir/index.php');
$this->assertEqual('/sub_dir/', TestCakeSession::$path);
}
/**
* testCakeSessionPathEmpty
*
* @access public
* @return void
*/
function testCakeSessionPathEmpty() {
TestCakeSession::init('');
$this->assertEqual('/', TestCakeSession::$path, 'Session path is empty, with "" as $base needs to be / %s');
}
/**
* testCakeSessionPathContainsParams
*
* @access public
* @return void
*/
function testCakeSessionPathContainsQuestion() {
TestCakeSession::init('/index.php?');
$this->assertEqual('/', TestCakeSession::$path);
}
/**
* testCheck method
*