You are here

protected function AccessTest::setUp in Apigee Edge 8

Overrides ApigeeEdgeFunctionalTestBase::setUp

File

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

Class

AccessTest
Teams module access test.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->teamStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team');
  $this->teamAppStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team_app');
  $this->teamRoleStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team_role');
  $this->teamMemberRoleStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team_member_role');
  $this->teamMembershipManager = $this->container
    ->get('apigee_edge_teams.team_membership_manager');
  $this->teamPermissionHandler = $this->container
    ->get('apigee_edge_teams.team_permissions');
  $this->state = $this->container
    ->get('state');
  $team_entity_type = $this->container
    ->get('entity_type.manager')
    ->getDefinition('team');
  $team_app_entity_type = $this->container
    ->get('entity_type.manager')
    ->getDefinition('team_app');

  /** @var \Drupal\Core\Entity\Routing\EntityRouteProviderInterface $provider */
  foreach ($this->container
    ->get('entity_type.manager')
    ->getRouteProviders('team') as $provider) {
    foreach ($provider
      ->getRoutes($team_entity_type) as $id => $route) {
      $this->teamEntityRoutes[$id] = $route;
    }
  }

  /** @var \Drupal\Core\Entity\Routing\EntityRouteProviderInterface $provider */
  foreach ($this->container
    ->get('entity_type.manager')
    ->getRouteProviders('team_app') as $provider) {
    foreach ($provider
      ->getRoutes($team_app_entity_type) as $id => $route) {
      $this->teamAppEntityRoutes[$id] = $route;
    }
  }

  // Skip api key routes. These are tested separately.
  $this->teamAppEntityRoutes = array_filter($this->teamAppEntityRoutes, function (Route $route) {
    return strpos($route
      ->getPath(), '{consumer_key}') === FALSE;
  });
  $this->team = $this->teamStorage
    ->create([
    'name' => mb_strtolower($this
      ->getRandomGenerator()
      ->name()),
  ]);
  $this->team
    ->save();
  $this->teamApp = $this->teamAppStorage
    ->create([
    'name' => mb_strtolower($this
      ->getRandomGenerator()
      ->name()),
    'companyName' => $this->team
      ->getName(),
  ]);
  $this->teamApp
    ->save();
  $this->account = $this
    ->createAccount();
  $this->nonTeamMemberAccount = $this
    ->createAccount();
  $this->teamMemberAccount = $this
    ->createAccount();
  $this->teamMembershipManager
    ->addMembers($this->team
    ->getName(), [
    $this->teamMemberAccount
      ->getEmail(),
  ]);

  // Create roles for team permissions.
  foreach (array_keys(static::TEAM_PERMISSION_MATRIX) as $permission) {
    $this->roles[$permission] = $this
      ->createRole([
      $permission,
    ], preg_replace('/[^a-z0-9_]+/', '_', $permission));
  }

  // Create roles for admin permissions.
  $this->roles['administer apigee edge'] = $this
    ->createRole([
    'administer apigee edge',
  ], 'administer_apigee_edge');
  $this->roles['administer team'] = $this
    ->createRole([
    'administer team',
  ], 'administer_team');
  $this->roles['manage team apps'] = $this
    ->createRole([
    'manage team apps',
  ], 'manage_team_apps');
}