diff --git a/src/core/classes/Session.php b/src/core/classes/Session.php index c690a16..0cb1c32 100644 --- a/src/core/classes/Session.php +++ b/src/core/classes/Session.php @@ -11,22 +11,23 @@ public function __construct(){ } public function setUserId($userId){ - $_SESSION['userId'] = $userId; + $this->set('userId', $userId); } public function getUserId($userID){ - return $_SESSION['userId']; + return $this->get('userId'); } public function getUserRights(){ - if(empty($_SESSION['userRights'])){ + $userRights = $this->get('userRights'); + if(empty($userRights)){ return array(); } - return $_SESSION['userRights']; + return $userRights; } public function setUserRights($userRights){ - $_SESSION['userRights'] = $userRights; + $this->set('userRights', $userRights); } /** @@ -59,6 +60,7 @@ public function get($key){ */ public function destroy($id = 0){ if(empty($id)){ + session_unset(); session_destroy(); } else { @@ -67,6 +69,7 @@ public function destroy($id = 0){ //change session to given session session_id($id); //delete session + session_unset(); session_destroy(); //return to own session session_id($tempSession); diff --git a/tests/SessionTest.php b/tests/SessionTest.php index f158721..6da23f2 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -17,6 +17,21 @@ public function testShouldReturnNullWithUnknownKey(){ $value = $this->session->get("unknownKey"); $this->assertEquals(null, $value); } + + public function testShouldReturnValueWhichIsStoredBefore(){ + $key = 'foo'; + $value = 'bar'; + $this->session->set($key, $value); + $this->assertEquals($value, $this->session->get($key)); + } + + public function testShouldNotReturnValueWhenSessionIsDestroyed(){ + $key = 'foo'; + $value = 'bar'; + $this->session->set($key, $value); + $this->session->destroy(); + $this->assertEquals(null, $this->session->get($key)); + } } ?> \ No newline at end of file