public function RulesEmailTest::testSubjectAndBody in Rules 8.3
Checks the From: and Reply-to: headers.
File
- tests/
src/ Kernel/ RulesEmailTest.php, line 45
Class
- RulesEmailTest
- Tests that emails actually go out with the send email action.
Namespace
Drupal\Tests\rules\KernelCode
public function testSubjectAndBody() {
// Create action to send email.
$action = $this->actionManager
->createInstance('rules_send_email');
// Add context values to action.
$action
->setContextValue('to', [
'mail@example.com',
])
->setContextValue('subject', 'subject')
->setContextValue('message', 'hello');
// Send email.
$action
->execute();
// Retrieve sent message.
$captured_emails = $this->container
->get('state')
->get('system.test_mail_collector');
$sent_message = end($captured_emails);
// Check to make sure that our subject and body are as expected.
$this
->assertEquals($sent_message['to'], 'mail@example.com');
$this
->assertEquals($sent_message['subject'], 'subject');
// Need to trim the email body to get rid of newline at end.
$this
->assertEquals(trim($sent_message['body']), 'hello');
}