/**
  * @depends testLoginHistory
  */
 public function testLoginHistoryPagination()
 {
     //Perform 20 more login
     $this->email = $this->valid_test_email;
     $this->password = $this->valid_test_password;
     $i = 1;
     while ($i <= 20) {
         $this->login();
         $i++;
     }
     //Fetch paginated records (page 1)
     $loginHistory = (new User())->getLoginHistory($this->email, 1, 10);
     $properties = ['first', 'before', 'items', 'current', 'last', 'next', 'total_pages', 'total_items', 'limit'];
     $response = Utils::validateObjectHasAllProperties($properties, $loginHistory);
     $this->assertTrue($response);
     $this->assertEquals(10, count($loginHistory->items));
     $this->assertEquals(1, $loginHistory->current);
     $this->assertEquals(1, $loginHistory->before);
     $this->assertEquals(2, $loginHistory->next);
     //fetch next set of records (page 2)
     $loginHistory = (new User())->getLoginHistory($this->email, 2, 10);
     $this->assertEquals(10, count($loginHistory->items));
     $this->assertEquals(2, $loginHistory->current);
     $this->assertEquals(1, $loginHistory->before);
     //page 3 should be empty
     $loginHistory = (new User())->getLoginHistory($this->email, 3, 10);
     $this->assertEquals(0, count($loginHistory->items));
 }
Ejemplo n.º 2
0
 public function testLogin()
 {
     //login user without email and password. This should throw an invalid user exception
     $this->email = "";
     $this->password = "";
     $this->loginAndCatchAuthenticationException();
     //set a valid email, and a wrong password
     $this->email = $this->valid_test_email;
     $this->password = '******';
     $this->loginAndCatchAuthenticationException();
     //set an invalid email, and a valid password
     $this->email = '*****@*****.**';
     $this->password = $this->valid_test_password;
     $this->loginAndCatchAuthenticationException();
     //Use valid credentials but an account that is inactive
     $this->email = $this->valid_test_email_2;
     $this->password = $this->valid_test_password;
     $this->loginAndCatchAuthenticationException();
     //Use valid credentials and an account that is active
     $this->email = $this->valid_test_email;
     $this->password = $this->valid_test_password;
     $response = $this->login();
     $this->assertNotEmpty($response, "Test Login Assertion: Valid email and valid password");
     $this->assertEquals($this->sample_user_type_name, $response->UserType->name);
     $relationShips = ['PasswordChanges', 'PasswordResets', 'LoginHistory', 'UserType'];
     //check that all of the following relationships are valid
     foreach ($relationShips as $aRelationShip) {
         $response->{$aRelationShip};
     }
     $requiredAttributes = ['id', 'email', 'password', 'status', 'created_at', 'updated_at', 'user_type_id'];
     $validate = Utils::validateObjectHasAllProperties($requiredAttributes, $response);
     $this->assertTrue($validate);
 }
Ejemplo n.º 3
0
 /**
  * Test for user type/role creation
  */
 public function testUserTypeCreation()
 {
     //Create a user type without a name (exception expected)
     $this->exception('', UserTypeException::class);
     //create two user types
     $admin = $this->createUserType('admin');
     $this->assertNotEmpty($admin);
     $user = $this->createUserType('user');
     $this->assertNotEmpty($user);
     //create another user type with the same name (exception expected)
     $this->exception('user', UserTypeException::class);
     //fetch all user types
     $userTypes = (new UserType())->getUserTypes();
     $this->assertNotEmpty($userTypes);
     $this->assertEquals(2, count($userTypes->toArray()));
     $requiredProperties = ['id', 'name', 'created_at', 'updated_at'];
     foreach ($userTypes as $type) {
         $response = Utils::validateObjectHasAllProperties($requiredProperties, $type);
         $this->assertTrue($response);
     }
 }