public function TeamInvitationsTest::testInvitationsList in Apigee Edge 8
Tests that a user can see their list of invitations.
File
- modules/
apigee_edge_teams/ tests/ src/ Functional/ TeamInvitationsTest.php, line 190
Class
- TeamInvitationsTest
- Team invitation test.
Namespace
Drupal\Tests\apigee_edge_teams\FunctionalCode
public function testInvitationsList() {
// Ensure "team_invitations" views page is installed.
$this
->assertNotNull(Views::getView('team_invitations'));
/** @var \Drupal\apigee_edge_teams\Entity\Storage\TeamInvitationStorageInterface $teamInvitationStorage */
$teamInvitationStorage = $this->entityTypeManager
->getStorage('team_invitation');
$selected_roles = [
TeamRoleInterface::TEAM_MEMBER_ROLE => TeamRoleInterface::TEAM_MEMBER_ROLE,
];
$teams = [
$this->teamA,
$this->teamB,
];
$companies = [
$this->teamA
->decorated(),
$this->teamB
->decorated(),
];
// Invite user to both teams.
foreach ($teams as $team) {
$this
->queueCompanyResponse($team
->decorated());
$teamInvitationStorage
->create([
'team' => [
'target_id' => $team
->id(),
],
'team_roles' => array_values(array_map(function (string $role) {
return [
'target_id' => $role,
];
}, $selected_roles)),
'recipient' => $this->accountUser
->getEmail(),
])
->save();
}
// Check that user can see both invitations.
$this
->drupalLogin($this->accountUser);
$invitationsUrl = Url::fromRoute('view.team_invitations.user', [
'user' => $this->accountUser
->id(),
]);
$this
->queueCompaniesResponse($companies);
$this
->drupalGet($invitationsUrl);
foreach ($teams as $team) {
$this
->assertSession()
->pageTextContains('Invitation to join ' . $team
->label());
}
// Delete a team and ensure related team invitation was deleted too.
$this
->queueCompanyResponse($this->teamA
->decorated());
$teamALabel = $this->teamA
->label();
$this->teamA
->delete();
$this
->queueCompaniesResponse($companies);
$this
->queueCompanyResponse($this->teamB
->decorated());
$this
->drupalGet($invitationsUrl);
$this
->assertSession()
->pageTextNotContains('Invitation to join ' . $teamALabel);
$this
->assertSession()
->pageTextContains('Invitation to join ' . $this->teamB
->label());
}