You are here

protected function AccessTest::teamRoleAccessTest in Apigee Edge 8

Tests team roles related UIs, permissions.

1 call to AccessTest::teamRoleAccessTest()
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 392

Class

AccessTest
Teams module access test.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

protected function teamRoleAccessTest() {

  // Ensure the current user is anonymous.
  if ($this->loggedInUser) {
    $this
      ->drupalLogout();
  }

  // The user is a member of the team and it has no teams related permission.
  // The user has the default "member" role in the team, the default member
  // role has no permissions.
  $this
    ->setUserPermissions([]);
  $this
    ->setTeamRolePermissionsOnUi(TeamRoleInterface::TEAM_MEMBER_ROLE, []);
  $this->teamMembershipManager
    ->addMembers($this->team
    ->getName(), [
    $this->account
      ->getEmail(),
  ]);

  // Create roles for every team membership level permission.
  $this
    ->drupalLogin($this->rootUser);
  foreach (array_keys(self::TEAM_MEMBER_PERMISSION_MATRIX) as $permission) {
    $this
      ->drupalPostForm(Url::fromRoute('entity.team_role.add_form'), [
      'label' => $permission,
      'id' => $permission,
    ], 'Save');
    $this
      ->setTeamRolePermissionsOnUi($permission, [
      $permission,
    ]);
  }

  // Grant team roles to the team member one by one.
  foreach (array_keys(self::TEAM_MEMBER_PERMISSION_MATRIX) as $permission) {
    $this
      ->drupalLogin($this->rootUser);
    $this->teamMemberRoleStorage
      ->addTeamRoles($this->account, $this->team, [
      $permission,
    ]);
    $this
      ->drupalLogin($this->account);
    $this
      ->validateTeamAccess();
    $this
      ->validateTeamAppAccess();
    $this
      ->drupalLogout();
  }

  // Revoke team roles from the team member one by one.
  foreach (array_keys(self::TEAM_MEMBER_PERMISSION_MATRIX) as $permission) {
    $this
      ->drupalLogin($this->rootUser);
    $this->teamMemberRoleStorage
      ->addTeamRoles($this->account, $this->team, [
      $permission,
    ]);
    $this
      ->drupalLogin($this->account);
    $this
      ->validateTeamAccess();
    $this
      ->validateTeamAppAccess();
    $this
      ->drupalLogout();
  }
}