1 mail.test BackdropHtmlToTextTestCase::testVeryLongLineWrap()

Tests that backdrop_html_to_text() wraps before 1000 characters.

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/simpletest/tests/mail.test, line 430
Test the Backdrop mailing system.

Class

BackdropHtmlToTextTestCase
Unit tests for backdrop_html_to_text().

Code

function testVeryLongLineWrap() {
  $input = 'Backdrop<br /><p>' . str_repeat('x', 2100) . '</p><br />Backdrop';
  $output = backdrop_html_to_text($input);
  // This awkward construct comes from includes/mail.inc lines 8-13.
  $eol = settings_get('mail_line_endings', MAIL_LINE_ENDINGS);
  // We must use strlen() rather than backdrop_strlen() in order to count
  // octets rather than characters.
  $line_length_limit = 1000 - backdrop_strlen($eol);
  $maximum_line_length = 0;
  foreach (explode($eol, $output) as $line) {
    // We must use strlen() rather than backdrop_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->pass($verbose);
  $this->assertTrue($maximum_line_length <= 1000, $verbose);
}