You are here

public function UserRoleRemoveTest::testRemoveNonExistingRole in Rules 8.3

Tests removing non-existing role from user.

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/UserRoleRemoveTest.php, line 74

Class

UserRoleRemoveTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\UserRoleRemove @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testRemoveNonExistingRole() {

  // Set-up a mock user with role 'editor'.
  $account = $this
    ->prophesizeEntity(UserInterface::class);
  $account
    ->hasRole('editor')
    ->willReturn(FALSE);
  $account
    ->removeRole('editor')
    ->shouldNotBeCalled();

  // Mock the 'editor' user role.
  $editor = $this
    ->prophesize(RoleInterface::class);
  $editor
    ->id()
    ->willReturn('editor');

  // Test removing of one role.
  $this->action
    ->setContextValue('user', $account
    ->reveal())
    ->setContextValue('roles', [
    $editor
      ->reveal(),
  ])
    ->execute();
  $this
    ->assertNotEquals($this->action
    ->autoSaveContext(), [
    'user',
  ], 'Action returns the user context name for auto saving.');
}