function SystemEmailToUsersOfRoleTest::testSendMailToTwoRoles
Tests sending an email to two roles.
@covers ::execute
File
-
tests/
src/ Unit/ Integration/ RulesAction/ SystemEmailToUsersOfRoleTest.php, line 145
Class
- SystemEmailToUsersOfRoleTest
- @coversDefaultClass \Drupal\rules\Plugin\RulesAction\SystemEmailToUsersOfRole @group RulesAction
Namespace
Drupal\Tests\rules\Unit\Integration\RulesActionCode
public function testSendMailToTwoRoles() {
// Mock the 'recipient' and 'moderator' roles.
$recipient = $this->prophesize(RoleInterface::class);
$recipient->id()
->willReturn('recipient');
$moderator = $this->prophesize(RoleInterface::class);
$moderator->id()
->willReturn('moderator');
// Use a language other than the site default.
$language = $this->prophesize(LanguageInterface::class);
$language->getId()
->willReturn('da');
$roles = [
$recipient->reveal(),
$moderator->reveal(),
];
$this->action
->setContextValue('roles', $roles)
->setContextValue('subject', 'subject')
->setContextValue('message', 'hello')
->setContextValue('language', $language->reveal());
$params = [
'subject' => 'subject',
'message' => 'hello',
];
$rids = [
'recipient',
'moderator',
];
$this->userStorage
->loadByProperties([
'roles' => $rids,
'status' => 1,
])
->willReturn([
$this->accounts[0],
]);
$this->mailManager
->mail('rules', 'rules_action_mail_' . $this->action
->getPluginId(), Argument::any(), $language->reveal()
->getId(), $params, NULL)
->willReturn([
'result' => TRUE,
])
->shouldBeCalledTimes(1);
$this->action
->execute();
$this->logger
->notice('Successfully sent email to %number out of %count users having the role(s) %roles', [
'%number' => 1,
'%count' => 1,
'%roles' => implode(', ', $rids),
])
->shouldHaveBeenCalled();
}