You are here

protected function ManageTeamAppsApiProductAccessTest::setUp in Apigee Edge 8

Overrides ApigeeEdgeFunctionalJavascriptTestBase::setUp

File

modules/apigee_edge_teams/tests/src/FunctionalJavascript/ManageTeamAppsApiProductAccessTest.php, line 88

Class

ManageTeamAppsApiProductAccessTest
Extra validation for API product access on team app forms.

Namespace

Drupal\Tests\apigee_edge_teams\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();

  // Users with manage team apps permissions can see private API products.
  $this
    ->config('apigee_edge_teams.team_settings')
    ->set('non_member_team_apps_visible_api_products', [
    'private',
  ])
    ->save();
  $this->account = $this
    ->createAccount([
    'manage team apps',
  ]);
  $apiProductStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('api_product');

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

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

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

  /** @var \Drupal\apigee_edge_teams\Entity\Storage\TeamStorageInterface $teamStorage */
  $teamStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team');

  // Use the machine name as both value because it makes easier the debugging.
  $teamName = strtolower($this
    ->randomMachineName());
  $team = $teamStorage
    ->create([
    'name' => $teamName,
    'displayName' => $teamName,
  ]);
  $team
    ->save();
  $this->team = $team;

  /** @var \Drupal\apigee_edge_teams\Entity\Storage\TeamAppStorageInterface $teamAppStorage */
  $teamAppStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('team_app');
  $teamApp = $teamAppStorage
    ->create([
    'name' => $this
      ->randomMachineName(),
    'companyName' => $this->team
      ->getName(),
  ]);
  $teamApp
    ->save();
  $this->teamApp = $teamApp;

  /** @var \Drupal\apigee_edge_teams\Entity\Controller\TeamAppCredentialControllerFactoryInterface $teamAppCredentialControllerFactory */
  $teamAppCredentialControllerFactory = $this->container
    ->get('apigee_edge_teams.controller.team_app_credential_controller_factory');
  $credentialController = $teamAppCredentialControllerFactory
    ->teamAppCredentialController($this->team
    ->id(), $this->teamApp
    ->getName());
  $credentials = $this->teamApp
    ->getCredentials();

  /** @var \Apigee\Edge\Api\Management\Entity\AppCredential $credential */
  $credential = reset($credentials);

  // Assign both public and private API products to the app.
  $credentialController
    ->addProducts($credential
    ->getConsumerKey(), [
    $this->publicProduct
      ->id(),
    $this->privateProduct
      ->id(),
  ]);
}