You are here

public function HtmlToTextTest::testVeryLongLineWrap in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Mail/HtmlToTextTest.php \Drupal\system\Tests\Mail\HtmlToTextTest::testVeryLongLineWrap()

Tests \Drupal\Core\Mail\MailFormatHelper::htmlToText() wrapping.

RFC 3676 says, "The Text/Plain media type is the lowest common denominator of Internet email, with lines of no more than 998 characters."

RFC 2046 says, "SMTP [RFC-821] allows a maximum of 998 octets before the next CRLF sequence."

RFC 821 says, "The maximum total length of a text line including the <CRLF> is 1000 characters."

File

core/modules/system/src/Tests/Mail/HtmlToTextTest.php, line 348
Contains \Drupal\system\Tests\Mail\HtmlToTextTest.

Class

HtmlToTextTest
Tests for \Drupal\Core\Mail\MailFormatHelper::htmlToText().

Namespace

Drupal\system\Tests\Mail

Code

public function testVeryLongLineWrap() {
  $input = 'Drupal<br /><p>' . str_repeat('x', 2100) . '</p><br />Drupal';
  $output = MailFormatHelper::htmlToText($input);
  $eol = Settings::get('mail_line_endings', PHP_EOL);
  $maximum_line_length = 0;
  foreach (explode($eol, $output) as $line) {

    // We must use strlen() rather than Unicode::strlen() in order to count
    // octets rather than characters.
    $maximum_line_length = max($maximum_line_length, strlen($line . $eol));
  }
  $verbose = 'Maximum line length found was ' . $maximum_line_length . ' octets.';
  $this
    ->assertTrue($maximum_line_length <= 1000, $verbose);
}