You are here

public function UserUnblockTest::testUnblockUser in Rules 8.3

Test execute() method for users with different status.

@dataProvider userProvider

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/UserUnblockTest.php, line 66

Class

UserUnblockTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\UserUnblock @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testUnblockUser($active, $authenticated, $expects, $autosave_names) {

  // Set-up a mock user.
  $account = $this
    ->prophesizeEntity(UserInterface::class);

  // Mock isBlocked.
  $account
    ->isBlocked()
    ->willReturn(!$active);

  // Mock isAuthenticated.
  $account
    ->isAuthenticated()
    ->willReturn($authenticated);

  // Mock activate.
  $account
    ->activate()
    ->shouldBeCalledTimes($expects);

  // We do not expect to call the 'save' method because the user should be
  // auto-saved later.
  $account
    ->save()
    ->shouldNotBeCalled();

  // Test unblocking the user.
  $this->action
    ->setContextValue('user', $account
    ->reveal())
    ->execute();
  $this
    ->assertEquals($this->action
    ->autoSaveContext(), $autosave_names, 'Action returns correct context name for auto saving.');
}