function HtmlToTextTest::assertHtmlToText

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\Mail\HtmlToTextTest::assertHtmlToText()
  2. 10 core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\Mail\HtmlToTextTest::assertHtmlToText()
  3. 9 core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php \Drupal\Tests\system\Functional\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().

File

core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php, line 55

Class

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

Namespace

Drupal\Tests\system\Functional\Mail

Code

protected function assertHtmlToText($html, $text, $message, $allowed_tags = NULL) {
  preg_match_all('/<([a-z0-6]+)/', mb_strtolower($html), $matches);
  $tested_tags = implode(', ', array_unique($matches[1]));
  $message .= ' (' . $tested_tags . ')';
  $result = MailFormatHelper::htmlToText($html, $allowed_tags);
  $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);
}

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