You are here

public function TeamListBuilderTest::testTeamListCache in Apigee Edge 8

Tests team list cache.

File

modules/apigee_edge_teams/tests/src/Functional/TeamListBuilderTest.php, line 164

Class

TeamListBuilderTest
Apigee Edge Teams list builder tests.

Namespace

Drupal\Tests\apigee_edge_teams\Functional

Code

public function testTeamListCache() {
  $companies = [
    $this->teamA
      ->decorated(),
    $this->teamB
      ->decorated(),
  ];

  // aMemberAccount should only see teamA.
  $this
    ->drupalLogin($this->aMemberAccount);
  $this
    ->queueCompaniesResponse($companies);
  $this
    ->queueDeveloperResponse($this->aMemberAccount, 200, [
    'companies' => [
      $this->teamA
        ->id(),
    ],
  ]);
  $this
    ->drupalGet(Url::fromRoute('entity.team.collection'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains($this->teamA
    ->label());
  $assert
    ->pageTextNotContains($this->teamB
    ->label());
  $this
    ->drupalLogout();

  // bMemberAccount should only see teamB.
  $this
    ->drupalLogin($this->bMemberAccount);
  $this
    ->queueCompaniesResponse($companies);
  $this
    ->queueDeveloperResponse($this->bMemberAccount, 200, [
    'companies' => [
      $this->teamB
        ->id(),
    ],
  ]);
  $this
    ->drupalGet(Url::fromUserInput('/teams'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextNotContains($this->teamA
    ->label());
  $assert
    ->pageTextContains($this->teamB
    ->label());
  $this
    ->drupalLogout();

  // cMemberAccount should not see any teams.
  $this
    ->drupalLogin($this->cMemberAccount);
  $this
    ->queueCompaniesResponse($companies);
  $this
    ->queueDeveloperResponse($this->cMemberAccount);
  $this
    ->queueDeveloperResponse($this->cMemberAccount);
  $this
    ->drupalGet(Url::fromUserInput('/teams'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextNotContains($this->teamA
    ->label());
  $assert
    ->pageTextNotContains($this->teamB
    ->label());

  // Give cMemberAccount permission to view all teams.
  $this->cMemberAccount
    ->addRole($this->customRole);
  $this->cMemberAccount
    ->save();

  // cMemberAccount should see both teams now.
  $this
    ->queueCompaniesResponse($companies);
  $this
    ->drupalGet(Url::fromUserInput('/teams'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains($this->teamA
    ->label());
  $assert
    ->pageTextContains($this->teamB
    ->label());
}