You are here

public function HtmlToTextTest::testVeryLongLineWrap in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php \Drupal\Tests\system\Functional\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/tests/src/Functional/Mail/HtmlToTextTest.php, line 350

Class

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

Namespace

Drupal\Tests\system\Functional\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 mb_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);
}