You are here

public function ManageTeamAppsApiProductAccessTest::testManageTeamAppsApiProductAccess in Apigee Edge 8

Test API product access of a user with Manage team apps permission.

File

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

Class

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

Namespace

Drupal\Tests\apigee_edge_teams\FunctionalJavascript

Code

public function testManageTeamAppsApiProductAccess() {
  $assert_session = $this
    ->assertSession();
  $message = 'You are not member of this team. You may see APIs here that a team member can not see.';
  $verifyApiProductAccessOnAddForm = function (WebDriverWebAssert $assert_session, string $message) {

    // Based on the default configuration a user with "Manage team apps"
    // permission should see the private API product but not the public
    // or the internal one.
    $this
      ->assertSession()
      ->pageTextContains($this->privateProduct
      ->label());
    $this
      ->assertSession()
      ->pageTextNotContains($this->publicProduct
      ->label());
    $this
      ->assertSession()
      ->pageTextNotContains($this->internalProduct
      ->label());
  };
  $this
    ->drupalLogin($this->account);

  // Validate team app add forms.
  $this
    ->drupalGet($this->teamApp
    ->toUrl('add-form'));
  $verifyApiProductAccessOnAddForm($assert_session, $message);
  $assert_session
    ->selectExists('Owner')
    ->selectOption($this->team
    ->id());
  $assert_session
    ->assertWaitOnAjaxRequest(1200000);
  $this
    ->assertSession()
    ->pageTextContains($message);
  $this
    ->drupalGet(Url::fromRoute('entity.team_app.add_form_for_team', [
    'team' => $this->team
      ->id(),
  ]));
  $verifyApiProductAccessOnAddForm($assert_session, $message);
  $this
    ->assertSession()
    ->pageTextContains($message);

  // Validate team app edit form.
  $this
    ->drupalGet($this->teamApp
    ->toUrl('edit-form'));

  // The page should contain both public and private API products, because
  // the team app is in association with the public API product.
  $this
    ->assertSession()
    ->pageTextContains($this->privateProduct
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($this->publicProduct
    ->label());

  // But it still should not contain the internal API product.
  $this
    ->assertSession()
    ->pageTextNotContains($this->internalProduct
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($message);
}