Skip to content
Permalink
Browse files

Add test for path containing question, and fix assignment of CakeSess…

…ion::path
  • Loading branch information...
predominant authored and markstory committed Jul 22, 2010
1 parent f556589 commit a63474a54d8fc481db58b9c89772be85110afde9
Showing with 33 additions and 24 deletions.
  1. +14 −23 cake/libs/cake_session.php
  2. +19 −1 cake/tests/cases/libs/cake_session.test.php
@@ -144,6 +144,7 @@ public static function init($base = null, $start = true) {
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 @@ protected static function _setPath($base = null) {
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 @@ protected function _setupDatabase() {
* @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();
}
@@ -96,17 +96,35 @@ function endTest() {
* @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
*

0 comments on commit a63474a

Please sign in to comment.
You can’t perform that action at this time.