You are here

protected function AccessTest::validateTeamAppAccess in Apigee Edge 8

Checks whether the user has access to team app pages.

Parameters

bool $admin_access: TRUE if the user has access to every team app page.

Throws

\Drupal\Core\Entity\EntityMalformedException

3 calls to AccessTest::validateTeamAppAccess()
AccessTest::teamAccessTest in modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
Tests team, team membership level and admin permissions.
AccessTest::teamExpansionTest in modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
Tests apigee_edge_teams_test module.
AccessTest::teamRoleAccessTest in modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
Tests team roles related UIs, permissions.

File

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

Class

AccessTest
Teams module access test.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

protected function validateTeamAppAccess(bool $admin_access = FALSE) {
  $route_ids_with_access = [];
  if ($admin_access) {
    $route_ids_with_access = array_map(function (string $route_id) {
      return str_replace('entity.team_app.', '', $route_id);
    }, array_keys($this->teamAppEntityRoutes));
  }
  else {

    // The developer is not necessarily a member of the team.
    foreach (array_keys(self::TEAM_MEMBER_PERMISSION_MATRIX) as $permission) {
      if (in_array($permission, $this->teamPermissionHandler
        ->getDeveloperPermissionsByTeam($this->team, $this->account))) {
        $route_ids_with_access = array_merge($route_ids_with_access, self::TEAM_MEMBER_PERMISSION_MATRIX[$permission]);
      }
    }
  }
  foreach ($this->teamAppEntityRoutes as $route_id => $route) {
    $short_route_id = str_replace('entity.team_app.', '', $route_id);
    $rel = str_replace('_', '-', $short_route_id);

    // First try to use the entity to generate the url - and with that
    // make sure the url parameter resolver works on the entity.
    if ($this->teamApp
      ->hasLinkTemplate($rel)) {
      $url = $this->teamApp
        ->toUrl($rel);
    }
    else {

      // If the route is not registered as link in entity links - because
      // it contains a route parameter that the entity can not resolve -
      // fallback to the URL resolver.
      $params = [
        'team' => $this->team
          ->id(),
      ];
      if (strpos($route
        ->getPath(), '{app}') !== FALSE) {
        $params['app'] = $this->teamApp
          ->getName();
      }
      $url = Url::fromRoute($route_id, $params);
    }
    if (in_array($short_route_id, $route_ids_with_access)) {
      $this
        ->validateAccess($url, Response::HTTP_OK);
    }
    else {
      $this
        ->validateAccess($url, Response::HTTP_FORBIDDEN);
    }
  }
}