You are here

protected function HtmlToTextTest::assertHtmlToText in Drupal 10

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

@internal

Parameters

string $html: The source HTML string to be converted.

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

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

array|null $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/tests/src/Functional/Mail/HtmlToTextTest.php
Tests allowing tags in \Drupal\Core\Mail\MailFormatHelper::htmlToText().
HtmlToTextTest::testDrupalHtmltoTextCollapsesWhitespace in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
Tests that whitespace is collapsed.
HtmlToTextTest::testDrupalHtmlToTextParagraphs in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
Tests that combinations of paragraph breaks, line breaks, linefeeds, and spaces are properly handled.
HtmlToTextTest::testFootnoteReferences in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
Tests that footnote references are properly generated.
HtmlToTextTest::testHeaderSeparation in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
Tests that headers are properly separated from surrounding text.

... See full list

File

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

Class

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

Namespace

Drupal\Tests\system\Functional\Mail

Code

protected function assertHtmlToText(string $html, string $text, string $message, ?array $allowed_tags = NULL) : void {
  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
    ->assertEquals($text, $result, Html::escape($message));
}