public function testLoginHistory() { //perform six login attempts, three successes and two failures, and one with an invalid email $this->email = $this->valid_test_email; $this->password = $this->valid_test_password; $this->login(); $this->login(); $this->login(); $this->password = '******'; $this->loginAndCatchAuthenticationException(); $this->loginAndCatchAuthenticationException(); //this should not be logged as email is invalid $this->email = 'wrong_email'; $this->loginAndCatchAuthenticationException(); //number of history logged for this user should be five $results = UserLoginHistory::query()->where("user_id = :user_id:")->bind(["user_id" => $this->user_id])->execute()->toArray(); $this->assertEquals(5, count($results)); //verify that the keys in the returned data are valid and complete $requiredKeys = ['id', 'user_id', 'ip_address', 'user_agent', 'date_logged', 'login_status']; $response = Utils::validateArrayHasAllKeys($requiredKeys, $results[0]); $this->assertTrue($response); }
/** * @param $email * @param $page * @param $limit * @return \stdClass * @throws UserAuthenticationException */ public function getLoginHistory($email, $page, $limit) { $user = $this->getUserByEmail($email); if ($user == false) { throw new UserAuthenticationException(ErrorMessages::EMAIL_DOES_NOT_EXIST); } return UserLoginHistory::getInstance()->setUserId($user->id)->fetchLoginHistory($page, $limit); }