function HtmlToTextTest::testDrupalHtmlToTextBlockTagToNewline

Tests the conversion of block-level HTML tags to plaintext with newlines.

File

core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php, line 219

Class

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

Namespace

Drupal\Tests\system\Unit\Mail

Code

public function testDrupalHtmlToTextBlockTagToNewline() : void {
  $input = <<<'EOT'
  [text]
  <blockquote>[blockquote]</blockquote>
  <br />[br]
  <dl><dt>[dl-dt]</dt>
  <dt>[dt]</dt>
  <dd>[dd]</dd>
  <dd>[dd-dl]</dd></dl>
  <h1>[h1]</h1>
  <h2>[h2]</h2>
  <h3>[h3]</h3>
  <h4>[h4]</h4>
  <h5>[h5]</h5>
  <h6>[h6]</h6>
  <hr />[hr]
  <ol><li>[ol-li]</li>
  <li>[li]</li>
  <li>[li-ol]</li></ol>
  <p>[p]</p>
  <ul><li>[ul-li]</li>
  <li>[li-ul]</li></ul>
  [text]
  EOT;
  $input = str_replace([
    "\r",
    "\n",
  ], '', $input);
  $output = MailFormatHelper::htmlToText($input);
  $this->assertDoesNotMatchRegularExpression('/\\][^\\n]*\\[/s', $output, 'Block-level HTML tags should force newlines');
  $output_upper = mb_strtoupper($output);
  $upper_input = mb_strtoupper($input);
  $upper_output = MailFormatHelper::htmlToText($upper_input);
  $this->assertEquals($output_upper, $upper_output, 'Tag recognition should be case-insensitive');
}

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