function HtmlToTextTest::testVeryLongLineWrap

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()
  2. 10 core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\Mail\HtmlToTextTest::testVeryLongLineWrap()
  3. 11.x core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Mail%21MailFormatHelper.php/function/MailFormatHelper%3A%3AhtmlToText/8.9.x" title="Transforms an HTML string into plain text, preserving its structure." class="local">\Drupal\Core\Mail\MailFormatHelper::htmlToText</a>().

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.