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 { 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 * @return void
*/ */
public function startup(&$controller) { public function __construct() {
/*if ($this->started() === false && $this->__active === true) { CakeSession::start();
$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;
} }
/** /**
@ -226,32 +184,12 @@ class SessionComponent extends Object {
} }
/** /**
* Starts Session if SessionComponent is used in Controller::beforeFilter(), * Returns a bool, whether or not the session has been started.
* or is called from
* *
* @return boolean * @return boolean
* @access protected
*/ */
protected function _start() { public function started() {
/* return CakeSession::started();
if ($this->started() === false) {
if (!$this->id() && parent::start()) {
parent::_checkValid();
} else {
parent::start();
}
}
return $this->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 { 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 * setUp method
* *
@ -87,8 +119,8 @@ class SessionComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
function setUp() { function setUp() {
$this->_session = Configure::read('Session'); parent::setUp();
$_SESSION = array(); $_SESSION = null;
} }
/** /**
@ -98,34 +130,22 @@ class SessionComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
function tearDown() { function tearDown() {
parent::tearDown();
CakeSession::destroy(); CakeSession::destroy();
Configure::write('Session', $this->_session);
} }
/** /**
* testSessionAutoStart method * ensure that session ids don't change when request action is called.
* *
* @access public * @access public
* @return void * @return void
*/ */
function testSessionAutoStart() { function testSessionIdConsistentAcrossRequestAction() {
$this->markTestSkipped('Autostarting is broken/disabled for now.');
Configure::write('Session.start', false);
$Session = new SessionComponent(); $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)); $this->assertTrue(isset($_SESSION));
$Object = new Object(); $Object = new Object();
$Session = new SessionComponent(); $Session = new SessionComponent();
$Session->start();
$expected = $Session->id(); $expected = $Session->id();
$result = $Object->requestAction('/session_test/session_id'); $result = $Object->requestAction('/session_test/session_id');
@ -135,29 +155,6 @@ class SessionComponentTest extends CakeTestCase {
$this->assertEqual($result, $expected); $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 * testSessionValid method
* *
@ -186,7 +183,6 @@ class SessionComponentTest extends CakeTestCase {
*/ */
function testSessionError() { function testSessionError() {
$Session = new SessionComponent(); $Session = new SessionComponent();
$this->assertFalse($Session->error()); $this->assertFalse($Session->error());
} }