3 namespace Drupal\Tests\Core\Mail;
5 use Drupal\Core\Mail\MailFormatHelper;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Mail\MailFormatHelper
12 class MailFormatHelperTest extends UnitTestCase {
17 public function testWrapMail() {
18 $delimiter = "End of header\n";
19 $long_file_name = $this->randomMachineName(64) . '.docx';
20 $headers_in_body = 'Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; name="' . $long_file_name . "\"\n";
21 $headers_in_body .= "Content-Transfer-Encoding: base64\n";
22 $headers_in_body .= 'Content-Disposition: attachment; filename="' . $long_file_name . "\"\n";
23 $headers_in_body .= 'Content-Description: ' . $this->randomMachineName(64);
24 $body = $this->randomMachineName(76) . ' ' . $this->randomMachineName(6);
25 $wrapped_text = MailFormatHelper::wrapMail($headers_in_body . $delimiter . $body);
26 list($processed_headers, $processed_body) = explode($delimiter, $wrapped_text);
28 // Check that the body headers were not wrapped even though some exceeded
30 $this->assertEquals($headers_in_body, $processed_headers, 'Headers in the body are not wrapped.');
31 // Check that the body text is wrapped.
32 $this->assertEquals(wordwrap($body, 77, " \n"), $processed_body, 'Body text is wrapped.');