Converting SessionComponent over to PHPUnit.

Adding a few getter/setter methods to fix visibility issues in the test cases.
This commit is contained in:
mark_story 2010-06-09 17:15:34 -04:00
parent 255d0c9d4f
commit 2c6bf51bd2
2 changed files with 55 additions and 33 deletions

View file

@ -88,6 +88,28 @@ class SessionComponent extends CakeSession {
$this->__active = true;
}
/**
* Check if the session is active. Returns the private __active flag.
*
* @return boolean
*/
public function active() {
return $this->__active;
}
/**
* Get / Set the userAgent
*
* @param string $userAgent Set the userAgent
* @return void
*/
public function userAgent($userAgent = null) {
if ($userAgent) {
$this->_userAgent = $userAgent;
}
return $this->_userAgent;
}
/**
* Used to write a value to a session key.
*

View file

@ -108,20 +108,20 @@ class SessionComponentTest extends CakeTestCase {
*/
function testSessionAutoStart() {
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$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);
$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 = new SessionComponent();
$Session->start();
$expected = $Session->id();
@ -139,17 +139,17 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionActivate() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertTrue($Session->__active);
$this->assertTrue($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->__active);
$this->assertTrue($Session->active());
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$Session = new SessionComponent();
$this->assertFalse($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->__active);
$this->assertTrue($Session->active());
Configure::write('Session.start', true);
$Session->destroy();
}
@ -161,25 +161,25 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionValid() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertTrue($Session->valid());
$Session->_userAgent = 'rweerw';
$Session->userAgent('rweerw');
$this->assertFalse($Session->valid());
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$Session = new SessionComponent();
$this->assertFalse($Session->active());
$this->assertFalse($Session->valid());
Configure::write('Session.start', true);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->time = $Session->read('Config.time') + 1;
$this->assertFalse($Session->valid());
Configure::write('Session.checkAgent', false);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->time = $Session->read('Config.time') + 1;
$this->assertFalse($Session->valid());
Configure::write('Session.checkAgent', true);
@ -192,13 +192,13 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionError() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->error());
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$Session = new SessionComponent();
$this->assertFalse($Session->active());
$this->assertFalse($Session->error());
Configure::write('Session.start', true);
}
@ -210,9 +210,9 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionReadWrite() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->read('Test'));
$this->assertNull($Session->read('Test'));
$this->assertTrue($Session->write('Test', 'some value'));
$this->assertEqual($Session->read('Test'), 'some value');
@ -237,7 +237,7 @@ class SessionComponentTest extends CakeTestCase {
$Session->delete('Test');
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->write('Test', 'some value'));
$Session->write('Test', 'some value');
$this->assertFalse($Session->read('Test'));
@ -251,7 +251,7 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionDelete() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->delete('Test'));
@ -259,7 +259,7 @@ class SessionComponentTest extends CakeTestCase {
$this->assertTrue($Session->delete('Test'));
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertFalse($Session->delete('Test'));
Configure::write('Session.start', true);
@ -272,7 +272,7 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionCheck() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->check('Test'));
@ -281,7 +281,7 @@ class SessionComponentTest extends CakeTestCase {
$Session->delete('Test');
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertFalse($Session->check('Test'));
Configure::write('Session.start', true);
@ -294,7 +294,7 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionFlash() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertNull($Session->read('Message.flash'));
@ -321,7 +321,7 @@ class SessionComponentTest extends CakeTestCase {
*/
function testSessionId() {
unset($_SESSION);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertNull($Session->id());
}
@ -332,7 +332,7 @@ class SessionComponentTest extends CakeTestCase {
* @return void
*/
function testSessionDestroy() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertEqual($Session->read('Test'), 'some value');
@ -350,7 +350,7 @@ class SessionComponentTest extends CakeTestCase {
session_destroy();
Configure::write('Security.level', 'low');
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
@ -359,7 +359,7 @@ class SessionComponentTest extends CakeTestCase {
session_destroy();
Configure::write('Security.level', 'medium');
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
@ -368,7 +368,7 @@ class SessionComponentTest extends CakeTestCase {
session_destroy();
Configure::write('Security.level', 'high');
$Session =& new SessionComponent();
$Session = new SessionComponent();
$Session->write('Test', 'some value');
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);