You are here

public function RemoveSingleOgMembershipRoleActionTest::testExecute in Organic groups 8

Checks if the action can be performed correctly.

@covers ::execute @dataProvider executeProvider

Parameters

string $membership: The membership on which to perform the action.

string|null $default_role_name: The name of the role that is used by default by the action plugin, if no other role has been configured through the UI.

string $expected_role_name: The name of the role that is expected to be removed from the membership after the action has been executed.

Overrides ActionTestBase::testExecute

File

tests/src/Kernel/Action/RemoveSingleOgMembershipRoleActionTest.php, line 37

Class

RemoveSingleOgMembershipRoleActionTest
Tests the RemoveSingleOgMembershipRole action plugin.

Namespace

Drupal\Tests\og\Kernel\Action

Code

public function testExecute($membership, $default_role_name = NULL, $expected_role_name = NULL) {

  /** @var \Drupal\og\Plugin\Action\AddSingleOgMembershipRole $plugin */
  $configuration = !empty($default_role_name) ? [
    'role_name' => $default_role_name,
  ] : [];
  $plugin = $this
    ->getPlugin($configuration);
  $plugin
    ->execute($this->memberships[$membership]);
  $has_role = (bool) array_filter($this->memberships[$membership]
    ->getRoles(), function (OgRole $role) use ($expected_role_name) {
    return $role
      ->getName() === $expected_role_name;
  });
  $this
    ->assertFalse($has_role);
}