You are here

protected function AccessTest::teamExpansionTest in Apigee Edge 8

Tests apigee_edge_teams_test module.

1 call to AccessTest::teamExpansionTest()
AccessTest::testAccess in modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
Tests team, team membership level and admin permissions, team roles.

File

modules/apigee_edge_teams/tests/src/Functional/AccessTest.php, line 438

Class

AccessTest
Teams module access test.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

protected function teamExpansionTest() {

  // Ensure that the apigee_edge_teams_test module properly extends the team
  // role permission UI.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet(Url::fromRoute('apigee_edge_teams.settings.team.permissions'));

  // Check whether the permission group labels and the permission labels and
  // descriptions are visible.
  $this
    ->assertSession()
    ->pageTextContains('Apigee Edge Teams: Testing');
  $this
    ->assertSession()
    ->pageTextContains('Team permission test');
  $this
    ->assertSession()
    ->pageTextContains('Team permission test 1');
  $this
    ->assertSession()
    ->pageTextContains('This is the 1st team test permission.');
  $this
    ->assertSession()
    ->pageTextContains('Team permission test 2');
  $this
    ->assertSession()
    ->pageTextContains('Team permission test 3');
  $this
    ->assertSession()
    ->pageTextContains('This is the 3rd team test permission.');
  $this
    ->assertSession()
    ->pageTextContains('Team permission test 4');

  // Change the username to grant every team permission to the user in
  // apigee_edge_teams_test_apigee_edge_teams_developer_permissions_by_team_alter().
  // It is not necessary to save the developer associated with this user.
  $this
    ->disableUserPresave();
  $this->account
    ->setUsername(APIGEE_EDGE_TEAMS_TEST_SPECIAL_USERNAME_WITH_ALL_TEAM_PERMISSIONS);
  $this->account
    ->save();
  $this
    ->enableUserPresave();

  // Make sure that the user is no longer a member of the team anymore.
  if (in_array($this->team
    ->id(), $this->teamMembershipManager
    ->getTeams($this->account
    ->getEmail()))) {
    $this->teamMembershipManager
      ->removeMembers($this->team
      ->getName(), [
      $this->account
        ->getEmail(),
    ]);
  }
  $this
    ->assertNotContains($this->team
    ->id(), $this->teamMembershipManager
    ->getTeams($this->account
    ->getEmail()));
  $this
    ->drupalLogin($this->account);

  // Even if the account is not member of the team it should have access all
  // team related UIs that a team permission can grant access.
  // (The user can still not CRUD teams but it can access to the teams list.)
  $this
    ->validateTeamAccess();
  $this
    ->validateTeamAppAccess();

  // Now it can not just access to the team list, but it can see all teams
  // in the list and access all team related UIs because it has all team
  // permissions.
  $this->state
    ->set(APIGEE_EDGE_TEAMS_TEST_SPECIAL_USERNAME_CAN_VIEW_ANY_TEAM_STATE_KEY, TRUE);
  $this
    ->validateAccess($this->team
    ->toUrl(), Response::HTTP_OK);
}