public function TeamMembershipManagerTest::testTeamMembershipManager in Apigee Edge 8
Tests team membership manager service.
File
- modules/
apigee_edge_teams/ tests/ src/ Functional/ TeamMembershipManagerTest.php, line 114
Class
- TeamMembershipManagerTest
- Team membership manager service test.
Namespace
Drupal\Tests\apigee_edge_teams\FunctionalCode
public function testTeamMembershipManager() {
$team_membership_manager = $this->container
->get('apigee_edge_teams.team_membership_manager');
$team_membership_cache = $this->container
->get('apigee_edge_teams.cache.company_membership_object');
// Ensure that the company's member list is empty.
foreach ($this->developers as $developer) {
$this
->assertEmpty($developer
->getCompanies());
$this
->assertEmpty($team_membership_manager
->getTeams($developer
->getEmail()));
$this
->assertEmpty($team_membership_manager
->getMembers($this->team
->getName()));
}
// Ensure that team membership cache is empty.
$this
->assertEmpty($team_membership_cache
->getMembership($this->team
->getName())
->getMembers());
// Add developers to the team and check whether the related membership
// service functions work properly.
$team_membership_manager
->addMembers($this->team
->getName(), [
$this->developers[0]
->getEmail(),
$this->developers[1]
->getEmail(),
]);
foreach ($this->developers as $developer) {
$this
->assertContains($this->team
->getName(), $team_membership_manager
->getTeams($developer
->getEmail()));
$this
->assertContains($developer
->getEmail(), $team_membership_manager
->getMembers($this->team
->getName()));
// Check whether the team membership is correctly cached.
$this
->assertArrayHasKey($developer
->getEmail(), $team_membership_cache
->getMembership($this->team
->getName())
->getMembers());
}
// Remove developers from the team and check whether the related
// membership service functions work properly.
foreach ($this->developers as $developer) {
$team_membership_manager
->removeMembers($this->team
->getName(), [
$developer
->getEmail(),
]);
$this
->assertNotContains($this->team
->getName(), $team_membership_manager
->getTeams($developer
->getEmail()));
$this
->assertNotContains($developer
->getEmail(), $team_membership_manager
->getMembers($this->team
->getName()));
// Check whether the team membership is correctly cached.
$this
->assertArrayNotHasKey($developer
->getEmail(), $team_membership_cache
->getMembership($this->team
->getName())
->getMembers());
}
// Ensure that team membership cache is empty.
$this
->assertEmpty($team_membership_cache
->getMembership($this->team
->getName())
->getMembers());
// Add developer to company then delete developer and check whether the
// developer is no longer member of the team.
$team_membership_manager
->addMembers($this->team
->getName(), [
$this->developers[0]
->getEmail(),
]);
$this->developerStorage
->delete([
$this->developers[0],
]);
$this
->assertNotContains($this->developers[0]
->getEmail(), $team_membership_manager
->getMembers($this->team
->getName()));
// Check whether the team membership is correctly cached.
$this
->assertArrayNotHasKey($this->developers[0]
->getEmail(), $team_membership_cache
->getMembership($this->team
->getName())
->getMembers());
// Delete the team and ensure that the team is removed from the team
// membership cache.
$this->teamStorage
->delete([
$this->team,
]);
$this
->assertNull($team_membership_cache
->getMembership($this->team
->getName()));
}