Skip to content

Commit

Permalink
refs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Sattler committed Mar 31, 2013
1 parent 8d65509 commit f2c2925
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/classes/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -59,6 +60,7 @@ public function get($key){
*/
public function destroy($id = 0){
if(empty($id)){
session_unset();
session_destroy();
}
else {
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions tests/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

?>

0 comments on commit f2c2925

Please sign in to comment.