You are here

public function HtmlToTextTest::testVeryLongLineWrap in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php \Drupal\Tests\system\Functional\Mail\HtmlToTextTest::testVeryLongLineWrap()
  2. 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 333

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));
  }

  // Verify that the maximum line length found was less than or equal to 1000
  // characters as per RFC 821.
  $this
    ->assertLessThanOrEqual(1000, $maximum_line_length);
}