From 7401b0c70f103f16afa51fd720be31d09d833a68 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 3 Jun 2009 16:22:00 +0000 Subject: [PATCH 1/2] Updating Session path handling to fix cases when path = ''. Test cases added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8186 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/session.php | 13 ++++++++----- cake/tests/cases/libs/session.test.php | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cake/libs/session.php b/cake/libs/session.php index c65d7de0b..c90318c9a 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -137,20 +137,23 @@ class CakeSession extends Object { $this->time = time(); if ($start === true) { - $this->host = env('HTTP_HOST'); - $this->path = '/'; - if (strpos($base, '?') === false && strpos($base, 'index.php') === false) { + if (!empty($base)) { $this->path = $base; + if (strpos($base, 'index.php') !== false) { + $this->path = str_replace('index.php', '', $base); + } + if (strpos($base, '?') !== false) { + $this->path = str_replace('?', '', $base); + } } + $this->host = env('HTTP_HOST'); if (strpos($this->host, ':') !== false) { $this->host = substr($this->host, 0, strpos($this->host, ':')); } - if (!class_exists('Security')) { App::import('Core', 'Security'); } - $this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout')); $this->security = Configure::read('Security.level'); } diff --git a/cake/tests/cases/libs/session.test.php b/cake/tests/cases/libs/session.test.php index 433c1747e..f74d626f8 100644 --- a/cake/tests/cases/libs/session.test.php +++ b/cake/tests/cases/libs/session.test.php @@ -76,6 +76,12 @@ class SessionTest extends CakeTestCase { function testSessionPath() { $Session = new CakeSession('/index.php'); $this->assertEqual('/', $Session->path); + + $Session = new CakeSession('/sub_dir/index.php'); + $this->assertEqual('/sub_dir/', $Session->path); + + $Session = new CakeSession(''); + $this->assertEqual('/', $Session->path, 'Session path is empty, with "" as $base needs to be / %s'); } /** * testCheck method From f983340d217d604f42ef07c1bb2f3502468c653e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 3 Jun 2009 16:23:35 +0000 Subject: [PATCH 2/2] Changing setUp() and tearDown() to startTest() and endTest(). Fixing test failures when app/controllers/pages_controller.php or app/views/pages/home.ctp was present. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8187 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/dispatcher.test.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index a50037de8..fd0fff3b9 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -493,7 +493,7 @@ class DispatcherTest extends CakeTestCase { * @access public * @return void */ - function setUp() { + function startTest() { $this->_get = $_GET; $_GET = array(); $this->_post = $_POST; @@ -512,7 +512,11 @@ class DispatcherTest extends CakeTestCase { $this->_vendorPaths = Configure::read('vendorPaths'); $this->_pluginPaths = Configure::read('pluginPaths'); $this->_viewPaths = Configure::read('viewPaths'); + $this->_controllerPaths = Configure::read('controllerPaths'); $this->_debug = Configure::read('debug'); + + Configure::write('controllerPaths', Configure::corePaths('controller')); + Configure::write('viewPaths', Configure::corePaths('view')); } /** * tearDown method @@ -520,7 +524,7 @@ class DispatcherTest extends CakeTestCase { * @access public * @return void */ - function tearDown() { + function endTest() { $_GET = $this->_get; $_POST = $this->_post; $_FILES = $this->_files; @@ -530,6 +534,7 @@ class DispatcherTest extends CakeTestCase { Configure::write('vendorPaths', $this->_vendorPaths); Configure::write('pluginPaths', $this->_pluginPaths); Configure::write('viewPaths', $this->_viewPaths); + Configure::write('controllerPaths', $this->_controllerPaths); Configure::write('debug', $this->_debug); } /**