/** * @test * @covers SlimApp\Session::delete * @uses SlimApp\Session::set */ public function delete_deletes_the_session_variable() { Session::set('UserId', 100); Session::delete('UserId'); $result = Session::get('UserId'); $this->assertFalse($result); }
/** * Logs the user in, ie. sets the session variable UserId for correct login data * * @param string $username * @param string $password * @return boolean True in case of success, false instead */ public function login($username, $password) { $where = '`username` = \'' . $username . '\' AND `password` = \'' . $password . '\''; $user = $this->userMapper->findRow($where); if (false !== $user) { Session::set('UserId', $user->getUserId()); return true; } return false; }
/** * @test * @covers SlimApp\Authentication::logout * @uses SlimApp\Session::delete * @uses SlimApp\Session::set */ public function logout_deletes_the_UserId_session_variable_if_it_was_set() { // Clean the session before the tests Session::delete('UserId'); // Logout called by a guest user $authentication = new Authentication(); $authentication->logout(); $userIdAfterGuestLogout = Session::get('UserId'); // Logged in user Session::set('UserId', 123); $authentication->logout(); $userIdAfterLoggedInUserLogout = Session::get('UserId'); $this->assertFalse($userIdAfterGuestLogout); $this->assertFalse($userIdAfterLoggedInUserLogout); }