RulesEmailTest.php in Rules 8.3
File
tests/src/Kernel/RulesEmailTest.php
View source
<?php
namespace Drupal\Tests\rules\Kernel;
class RulesEmailTest extends RulesKernelTestBase {
protected $actionManager;
protected static $modules = [
'rules',
];
protected function setUp() : void {
parent::setUp();
$this->container
->get('config.factory')
->getEditable('system.mail')
->set('interface.default', 'test_mail_collector')
->save();
$this->container
->get('state')
->set('system.test_mail_collector', []);
$this->actionManager = $this->container
->get('plugin.manager.rules_action');
}
public function testSubjectAndBody() {
$action = $this->actionManager
->createInstance('rules_send_email');
$action
->setContextValue('to', [
'mail@example.com',
])
->setContextValue('subject', 'subject')
->setContextValue('message', 'hello');
$action
->execute();
$captured_emails = $this->container
->get('state')
->get('system.test_mail_collector');
$sent_message = end($captured_emails);
$this
->assertEquals($sent_message['to'], 'mail@example.com');
$this
->assertEquals($sent_message['subject'], 'subject');
$this
->assertEquals(trim($sent_message['body']), 'hello');
}
}
Classes
Name |
Description |
RulesEmailTest |
Tests that emails actually go out with the send email action. |