public function OgMembershipTest::testGetRolesIdsFromMembership in Organic groups 8
Tests that the role ids are being built properly by the membership.
@covers ::getRolesIds
File
- tests/
src/ Kernel/ Entity/ OgMembershipTest.php, line 793
Class
- OgMembershipTest
- Tests the OgMembership entity.
Namespace
Drupal\Tests\og\Kernel\EntityCode
public function testGetRolesIdsFromMembership() {
$entity_type_id = $this->group
->getEntityTypeId();
$bundle = $this->group
->bundle();
$og_extra_role = OgRole::create()
->setGroupType($entity_type_id)
->setGroupBundle($bundle)
->setName(mb_strtolower($this
->randomMachineName()));
$og_extra_role
->save();
$membership = OgMembership::create()
->setGroup($this->group)
->setOwner($this->user)
->addRole($og_extra_role);
$membership
->save();
$role_names = [
'member',
$og_extra_role
->getName(),
];
$expected_ids = array_map(function ($role_name) use ($entity_type_id, $bundle) {
return "{$entity_type_id}-{$bundle}-{$role_name}";
}, $role_names);
$actual_ids = $membership
->getRolesIds();
// Sort the two arrays before comparing so we can check the contents
// regardless of their order.
sort($expected_ids);
sort($actual_ids);
$this
->assertEquals($expected_ids, $actual_ids, 'Role ids are built properly.');
}