Removing dead properties and methods from SessionComponent.

Sessions should be started as soon as the component is constructed. So there is no reason to have an active()/activate() method.
This commit is contained in:
mark_story 2010-07-25 19:57:48 -04:00
parent 574bfe6b67
commit 977ffa96be
2 changed files with 43 additions and 109 deletions

View file

@ -34,54 +34,12 @@ if (!class_exists('cakesession')) {
class SessionComponent extends Object {
/**
* Used to determine if methods implementation is used, or bypassed
* Constructor
*
* @var boolean
* @access private
*/
private $__active = true;
/**
* Used to determine if request are from an Ajax request
*
* @var boolean
* @access private
*/
private $__bare = 0;
/**
* Startup method.
*
* @param object $controller Instantiating controller
* @return void
*/
public function startup(&$controller) {
/*if ($this->started() === false && $this->__active === true) {
$this->_start();
}*/
}
/**
* Starts Session on if 'Session.start' is set to false in core.php
*
* @param string $base The base path for the Session
* @return void
*/
public function activate($base = null) {
/*if ($this->__active === true) {
return;
}
parent::__construct($base);
$this->__active = true;*/
}
/**
* Check if the session is active. Returns the private __active flag.
*
* @return boolean
*/
public function active() {
return $this->__active;
public function __construct() {
CakeSession::start();
}
/**
@ -226,32 +184,12 @@ class SessionComponent extends Object {
}
/**
* Starts Session if SessionComponent is used in Controller::beforeFilter(),
* or is called from
* Returns a bool, whether or not the session has been started.
*
* @return boolean
* @access protected
*/
protected function _start() {
/*
if ($this->started() === false) {
if (!$this->id() && parent::start()) {
parent::_checkValid();
} else {
parent::start();
}
}
return $this->started();
*/
public function started() {
return CakeSession::started();
}
/**
* Returns whether the session is active or not
*
* @return boolean
* @access public
*/
public function isActive() {
return $this->__active;
}
}

View file

@ -80,6 +80,38 @@ class OrangeSessionTestController extends Controller {
*/
class SessionComponentTest extends CakeTestCase {
protected static $_sessionBackup;
/**
* fixtures
*
* @var string
*/
public $fixtures = array('core.session');
/**
* test case startup
*
* @return void
*/
public static function setupBeforeClass() {
self::$_sessionBackup = Configure::read('Session');
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 100,
'cookie' => 'test_suite'
));
}
/**
* cleanup after test case.
*
* @return void
*/
public static function teardownAfterClass() {
Configure::write('Session', self::$_sessionBackup);
}
/**
* setUp method
*
@ -87,8 +119,8 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->_session = Configure::read('Session');
$_SESSION = array();
parent::setUp();
$_SESSION = null;
}
/**
@ -98,34 +130,22 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function tearDown() {
parent::tearDown();
CakeSession::destroy();
Configure::write('Session', $this->_session);
}
/**
* testSessionAutoStart method
* ensure that session ids don't change when request action is called.
*
* @access public
* @return void
*/
function testSessionAutoStart() {
$this->markTestSkipped('Autostarting is broken/disabled for now.');
Configure::write('Session.start', false);
function testSessionIdConsistentAcrossRequestAction() {
$Session = new SessionComponent();
$this->assertFalse($Session->active());
$this->assertFalse($Session->started());
$Session->startup(new SessionTestController());
Configure::write('Session.start', true);
$Session = new SessionComponent();
$this->assertTrue($Session->active());
$this->assertFalse($Session->started());
$Session->startup(new SessionTestController());
$this->assertTrue(isset($_SESSION));
$Object = new Object();
$Session = new SessionComponent();
$Session->start();
$expected = $Session->id();
$result = $Object->requestAction('/session_test/session_id');
@ -135,29 +155,6 @@ class SessionComponentTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* testSessionActivate method
*
* @access public
* @return void
*/
function testSessionActivate() {
$this->markTestSkipped('Activation is not implemented right now, sessions are always on');
$Session = new SessionComponent();
$this->assertTrue($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->active());
Configure::write('Session.start', false);
$Session = new SessionComponent();
$this->assertFalse($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->active());
Configure::write('Session.start', true);
$Session->destroy();
}
/**
* testSessionValid method
*
@ -186,7 +183,6 @@ class SessionComponentTest extends CakeTestCase {
*/
function testSessionError() {
$Session = new SessionComponent();
$this->assertFalse($Session->error());
}