You are here

public function OgMembershipTest::testSaveRoleWithWrongGroupType in Organic groups 8

Tests saving a membership with a role with a different group type.

@covers ::preSave @dataProvider saveRoleWithWrongGroupTypeProvider

File

tests/src/Kernel/Entity/OgMembershipTest.php, line 329

Class

OgMembershipTest
Tests the OgMembership entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testSaveRoleWithWrongGroupType($group_entity_type_id, $group_bundle_id) {
  $group = EntityTest::create([
    'type' => 'entity_test',
    'name' => $this
      ->randomString(),
  ]);
  $group
    ->save();
  $this->groupTypeManager
    ->addGroup('entity_test', $group
    ->bundle());
  $wrong_role = OgRole::create()
    ->setGroupType($group_entity_type_id)
    ->setGroupBundle($group_bundle_id)
    ->setName(mb_strtolower($this
    ->randomMachineName()));
  $wrong_role
    ->save();
  $this
    ->expectException(EntityStorageException::class);
  Og::createMembership($group, $this->user)
    ->addRole($wrong_role)
    ->save();
}