Skip to content
Snippets Groups Projects
Commit d9220bf4 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3380698: Make EmailNotificationsTestTrait::assertMessagesSent() clearer...

Issue #3380698: Make EmailNotificationsTestTrait::assertMessagesSent() clearer by renaming variables
parent 4ef42b95
No related branches found
No related tags found
No related merge requests found
......@@ -56,40 +56,40 @@ trait EmailNotificationsTestTrait {
/**
* Asserts that all recipients received a given email.
*
* @param string $subject
* @param string $expected_subject
* The subject line of the email that should have been sent.
* @param string $body
* @param string $expected_body
* The beginning of the body text of the email that should have been sent.
*
* @see ::$emailRecipients
*/
protected function assertMessagesSent(string $subject, string $body): void {
protected function assertMessagesSent(string $expected_subject, string $expected_body): void {
$sent_messages = $this->getMails([
'subject' => $subject,
'subject' => $expected_subject,
]);
$this->assertNotEmpty($sent_messages);
$this->assertCount(count($this->emailRecipients), $sent_messages);
// Ensure the body is formatted the way the PHP mailer would do it.
$message = [
'body' => [$body],
$expected_message = [
'body' => [$expected_body],
];
$message = $this->container->get('plugin.manager.mail')
$expected_message = $this->container->get('plugin.manager.mail')
->createInstance('php_mail')
->format($message);
$body = $message['body'];
->format($expected_message);
$expected_body = $expected_message['body'];
foreach ($sent_messages as $message) {
$email = $message['to'];
foreach ($sent_messages as $sent_message) {
$email = $sent_message['to'];
$expected_langcode = $this->emailRecipients[$email];
$this->assertSame($expected_langcode, $message['langcode']);
$this->assertSame($expected_langcode, $sent_message['langcode']);
// The message, and every line in it, should have been sent in the
// expected language.
// @see automatic_updates_test_mail_alter()
$this->assertArrayHasKey('line_langcodes', $message);
$this->assertSame([$expected_langcode], $message['line_langcodes']);
$this->assertStringStartsWith($body, $message['body']);
$this->assertArrayHasKey('line_langcodes', $sent_message);
$this->assertSame([$expected_langcode], $sent_message['line_langcodes']);
$this->assertStringStartsWith($expected_body, $sent_message['body']);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment