You are here

protected function HtmlToTextTest::assertHtmlToText 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::assertHtmlToText()

Helper function to test \Drupal\Core\Mail\MailFormatHelper::htmlToText().

Parameters

$html: The source HTML string to be converted.

$text: The expected result of converting $html to text.

$message: A text message to display in the assertion message.

$allowed_tags: (optional) An array of allowed tags, or NULL to default to the full set of tags supported by \Drupal\Core\Mail\MailFormatHelper::htmlToText().

6 calls to HtmlToTextTest::assertHtmlToText()
HtmlToTextTest::testDrupalHtmlToTextArgs in core/modules/system/src/Tests/Mail/HtmlToTextTest.php
Tests allowing tags in \Drupal\Core\Mail\MailFormatHelper::htmlToText().
HtmlToTextTest::testDrupalHtmltoTextCollapsesWhitespace in core/modules/system/src/Tests/Mail/HtmlToTextTest.php
Test that whitespace is collapsed.
HtmlToTextTest::testDrupalHtmlToTextParagraphs in core/modules/system/src/Tests/Mail/HtmlToTextTest.php
Test that combinations of paragraph breaks, line breaks, linefeeds, and spaces are properly handled.
HtmlToTextTest::testFootnoteReferences in core/modules/system/src/Tests/Mail/HtmlToTextTest.php
Test that footnote references are properly generated.
HtmlToTextTest::testHeaderSeparation in core/modules/system/src/Tests/Mail/HtmlToTextTest.php
Test that headers are properly separated from surrounding text.

... See full list

File

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

Class

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

Namespace

Drupal\system\Tests\Mail

Code

protected function assertHtmlToText($html, $text, $message, $allowed_tags = NULL) {
  preg_match_all('/<([a-z0-6]+)/', Unicode::strtolower($html), $matches);
  $tested_tags = implode(', ', array_unique($matches[1]));
  $message .= ' (' . $tested_tags . ')';
  $result = MailFormatHelper::htmlToText($html, $allowed_tags);
  $pass = $this
    ->assertEqual($result, $text, Html::escape($message));
  $verbose = 'html = <pre>' . $this
    ->stringToHtml($html) . '</pre><br />' . 'result = <pre>' . $this
    ->stringToHtml($result) . '</pre><br />' . 'expected = <pre>' . $this
    ->stringToHtml($text) . '</pre>';
  $this
    ->verbose($verbose);
  if (!$pass) {
    $this
      ->pass("Previous test verbose info:<br />{$verbose}");
  }
}