Skip to content
Permalink
Browse files

Converting SessionComponent over to PHPUnit.

Adding a few getter/setter methods to fix visibility issues in the test cases.
  • Loading branch information...
markstory committed Jun 9, 2010
1 parent 255d0c9 commit 2c6bf51bd26ce4221cb41d02a0355af504797f18
@@ -88,6 +88,28 @@ public function activate($base = null) {
$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.
*
@@ -108,20 +108,20 @@ function tearDown() {
*/
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 @@ function testSessionAutoStart() {
* @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 @@ function testSessionActivate() {
* @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 @@ function testSessionValid() {
* @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 @@ function testSessionError() {
* @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 @@ function testSessionReadWrite() {
$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,15 +251,15 @@ function testSessionReadWrite() {
* @return void
*/
function testSessionDelete() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->delete('Test'));
$Session->write('Test', 'some value');
$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 @@ function testSessionDelete() {
* @return void
*/
function testSessionCheck() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertFalse($Session->check('Test'));
@@ -281,7 +281,7 @@ function testSessionCheck() {
$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 @@ function testSessionCheck() {
* @return void
*/
function testSessionFlash() {
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertNull($Session->read('Message.flash'));
@@ -321,7 +321,7 @@ function testSessionFlash() {
*/
function testSessionId() {
unset($_SESSION);
$Session =& new SessionComponent();
$Session = new SessionComponent();
$this->assertNull($Session->id());
}
@@ -332,7 +332,7 @@ function testSessionId() {
* @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 @@ function testSessionTimeout() {
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 @@ function testSessionTimeout() {
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 @@ function testSessionTimeout() {
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);

0 comments on commit 2c6bf51

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