Exemplo n.º 1
0
 /**
  * @test
  * @covers SlimApp\Session::exists
  */
 public function exists_returns_true_if_session_variable_exists_false_instead()
 {
     $resultNotSet = Session::exists('UserId');
     $_SESSION['UserId'] = 10;
     $resultSet = Session::exists('UserId');
     $this->assertFalse($resultNotSet);
     $this->assertTrue($resultSet);
 }
Exemplo n.º 2
0
 /**
  * Sets the current user using the UserId session variable and the data mapper
  */
 public function addLoggedInUserDataToContext()
 {
     if (Session::exists('UserId')) {
         $userId = Session::get('UserId');
         $where = '`UserId` = ' . $userId;
         $user = $this->userMapper->findRow($where);
         $this->context['user'] = $user->toArray();
     }
 }
Exemplo n.º 3
0
 /**
  * Logs the user out, ie. detroys the session varialbe UserId, if it exists
  */
 public function logout()
 {
     if (Session::exists('UserId')) {
         Session::delete('UserId');
     }
 }
Exemplo n.º 4
0
 /**
  * @test
  * @covers SlimApp\Authentication::login
  * @uses SlimApp\Session::delete
  * @uses SlimApp\Session::exists
  * @uses SlimApp\Session::get
  * @param string $findRowReturns
  * @param boolean $loginResult
  * @dataProvider provider_login_sets_UserId_session_variable_and_returns_true_if_login_data_correct_returns_false_otherwise
  */
 public function login_sets_UserId_session_variable_and_returns_true_if_login_data_correct_returns_false_otherwise($findRowReturns, $loginResult)
 {
     // Clean the session before the tests
     Session::delete('UserId');
     if ('user' === $findRowReturns) {
         $userId = 12;
         $user = $this->getMockBuilder('\\SlimApp\\User')->setMethods(['getUserId'])->getMock();
         $user->expects($this->once())->method('getUserId')->will($this->returnValue($userId));
         $resultFindRow = $user;
     } else {
         $userId = false;
         $resultFindRow = false;
     }
     $mapper = $this->getMockBuilder('\\SlimApp\\Db\\Mapper')->setMethods(['findRow'])->getMock();
     $mapper->expects($this->once())->method('findRow')->will($this->returnValue($resultFindRow));
     $authentication = new Authentication($mapper);
     $login = $authentication->login('username', 'password');
     $this->assertEquals($loginResult, $login);
     $this->assertEquals($loginResult, Session::exists('UserId'));
     $this->assertEquals($loginResult, $authentication->userLoggedIn());
     $this->assertEquals($userId, Session::get('UserId'));
 }