function HtmlToTextTest::stringToHtml

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php \Drupal\Tests\system\Functional\Mail\HtmlToTextTest::stringToHtml()
  2. 10 core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\Mail\HtmlToTextTest::stringToHtml()
  3. 11.x core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php \Drupal\Tests\system\Unit\Mail\HtmlToTextTest::stringToHtml()

Converts a string to its PHP source equivalent for display in test messages.

Parameters

$text: The text string to convert.

Return value

An HTML representation of the text string that, when displayed in a browser, represents the PHP source code equivalent of $text.

2 calls to HtmlToTextTest::stringToHtml()
HtmlToTextTest::assertHtmlToText in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
Helper function to test \Drupal\Core\Mail\MailFormatHelper::htmlToText().
HtmlToTextTest::testDrupalHtmlToTextBlockTagToNewline in core/modules/system/tests/src/Functional/Mail/HtmlToTextTest.php
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/tests/src/Functional/Mail/HtmlToTextTest.php, line 32

Class

HtmlToTextTest
Tests for <a href="/api/drupal/core%21lib%21Drupal%21Core%21Mail%21MailFormatHelper.php/function/MailFormatHelper%3A%3AhtmlToText/8.9.x" title="Transforms an HTML string into plain text, preserving its structure." class="local">\Drupal\Core\Mail\MailFormatHelper::htmlToText</a>().

Namespace

Drupal\Tests\system\Functional\Mail

Code

protected function stringToHtml($text) {
    return '"' . str_replace([
        "\n",
        ' ',
    ], [
        '\\n',
        '&nbsp;',
    ], Html::escape($text)) . '"';
}

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