You are here

public function HtmlToTextTest::testDrupalHtmlToTextBlockTagToNewline in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Mail/HtmlToTextTest.php \Drupal\system\Tests\Mail\HtmlToTextTest::testDrupalHtmlToTextBlockTagToNewline()

Test that text separated by block-level tags in HTML get separated by (at least) a newline in the plaintext version.

File

core/modules/system/src/Tests/Mail/HtmlToTextTest.php, line 219
Contains \Drupal\system\Tests\Mail\HtmlToTextTest.

Class

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

Namespace

Drupal\system\Tests\Mail

Code

public function testDrupalHtmlToTextBlockTagToNewline() {
  $input = '[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]';
  $output = MailFormatHelper::htmlToText($input);
  $pass = $this
    ->assertFalse(preg_match('/\\][^\\n]*\\[/s', $output), 'Block-level HTML tags should force newlines');
  if (!$pass) {
    $this
      ->verbose($this
      ->stringToHtml($output));
  }
  $output_upper = Unicode::strtoupper($output);
  $upper_input = Unicode::strtoupper($input);
  $upper_output = MailFormatHelper::htmlToText($upper_input);
  $pass = $this
    ->assertEqual($upper_output, $output_upper, 'Tag recognition should be case-insensitive');
  if (!$pass) {
    $this
      ->verbose($upper_output . '<br />should  be equal to <br />' . $output_upper);
  }
}