// Prepare render array.
$render =
['#markup' => Markup::
create($html)];
// Send a test message that mail_cancel_test_mail_alter should cancel.
\Drupal::
service('plugin.manager.mail'
)->
mail('mail_html_test', 'render_from_message_param', 'relative_url@example.com',
$language_interface->
getId(),
['message' =>
$render]);
// Retrieve sent message.
$captured_emails = \Drupal::
state()->
get('system.test_mail_collector'
);
$sent_message =
end($captured_emails);
// Wrap the expected HTML and assert.
$expected_html = MailFormatHelper::
wrapMail($expected_html);
$this->
assertSame($expected_html,
$sent_message['body'
], "Asserting that {
$attribute} is properly converted for mails."
);
} // Test protocol relative URLs.
foreach (['href', 'src'
] as $attribute) { // Reset the state variable that holds sent messages.
\Drupal::
state()->
set('system.test_mail_collector',
[]);
$html = "<
$tag_name $attribute=\"//example.com/protocol-relative\">protocol relative url in mail test</
$tag_name>";
$expected_html = "<
$tag_name $attribute=\"//example.com/protocol-relative\">protocol relative url in mail test</
$tag_name>";