You are here

public function SystemEmailToUsersOfRoleTest::testSendMailToOneRoles in Rules 8.3

Tests sending an email to one role.

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/SystemEmailToUsersOfRoleTest.php, line 102

Class

SystemEmailToUsersOfRoleTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\SystemEmailToUsersOfRole @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testSendMailToOneRoles() {

  // Mock the 'recipient' user role.
  $recipient = $this
    ->prophesize(RoleInterface::class);
  $recipient
    ->id()
    ->willReturn('recipient');
  $roles = [
    $recipient
      ->reveal(),
  ];
  $this->action
    ->setContextValue('roles', $roles)
    ->setContextValue('subject', 'subject')
    ->setContextValue('message', 'hello');
  $params = [
    'subject' => 'subject',
    'message' => 'hello',
  ];
  $rids = [
    'recipient',
  ];
  $this->userStorage
    ->loadByProperties([
    'roles' => $rids,
    'status' => 1,
  ])
    ->willReturn($this->accounts);
  $this->mailManager
    ->mail('rules', 'rules_action_mail_' . $this->action
    ->getPluginId(), Argument::any(), LanguageInterface::LANGCODE_SITE_DEFAULT, $params, NULL)
    ->willReturn([
    'result' => TRUE,
  ])
    ->shouldBeCalledTimes(3);
  $this->action
    ->execute();
  $this->logger
    ->notice('Successfully sent email to %number out of %count users having the role(s) %roles', [
    '%number' => 3,
    '%count' => count($this->accounts),
    '%roles' => implode(', ', $rids),
  ])
    ->shouldHaveBeenCalled();
}