You are here

protected function TeamApiProductAccessTest::setUp in Apigee Edge 8

Overrides ApigeeEdgeFunctionalTestBase::setUp

File

modules/apigee_edge_teams/tests/src/Functional/TeamApiProductAccessTest.php, line 119

Class

TeamApiProductAccessTest
Team-level API product access test.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->apiProductStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('api_product');
  $this->teamStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team');
  $this->teamMembershipManager = $this->container
    ->get('apigee_edge_teams.team_membership_manager');
  $this->teamApiProductAccessHandler = $this->container
    ->get('apigee_edge_teams.team_member_api_product_access_handler');
  $this->teamRoleStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team_role');
  $this->team = $this->teamStorage
    ->create([
    'name' => $this
      ->getRandomGenerator()
      ->name(),
  ]);
  $this->team
    ->save();
  foreach ([
    'developer',
    'team_member',
  ] as $developer_property) {
    $this->{$developer_property} = $this
      ->createAccount();
  }
  $this->teamMembershipManager
    ->addMembers($this->team
    ->id(), [
    $this->team_member
      ->getEmail(),
  ]);
  foreach (static::VISIBILITIES as $visibility) {

    /** @var \Drupal\apigee_edge\Entity\ApiProductInterface $api_product */
    $api_product = $this->apiProductStorage
      ->create([
      'name' => $this
        ->randomMachineName(),
      'displayName' => $this
        ->randomMachineName() . " ({$visibility})",
      'approvalType' => ApiProductInterface::APPROVAL_TYPE_AUTO,
    ]);
    $api_product
      ->setAttribute('access', $visibility);
    $api_product
      ->save();
    $this->apiProducts[$visibility] = $api_product;
  }

  // Ensure default API product access settings.
  // Logged-in users can only access to the public API products.
  $this
    ->config('apigee_edge.api_product_settings')
    ->set('access', [
    self::PUBLIC_VISIBILITY => [
      AccountInterface::AUTHENTICATED_ROLE,
    ],
    self::PRIVATE_VISIBILITY => [],
    self::INTERNAL_VISIBILITY => [],
  ])
    ->save();

  // Team members can only assign private API products to team apps but
  // they have view/view label access to public API products.
  $this
    ->changeTeamApiProductAccess(FALSE, TRUE, FALSE);
}