protected function TextPlainUnitTest::formatString

Formats an assertion message string.

Unlike format_string(),

  • all replacement tokens are exported via var_export() and sanitized for output, regardless of token type used (i.e., '@', '!', and '%' do not have any special meaning).
  • Replacement token values containing newlines are automatically wrapped into a PRE element to aid in debugging test failures.

Parameters

string $message: The assertion message string containing placeholders.

array $args: An array of replacement token values to inject into $message.

Return value

string The $message with exported replacement tokens, sanitized for HTML output.

See also

check_plain()

format_string()

4 calls to TextPlainUnitTest::formatString()
TextPlainUnitTest::assertNoRaw in drupal/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
Asserts that a raw string does not appear in $this->content.
TextPlainUnitTest::assertNoText in drupal/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
Asserts that a text string does not appear in the text-only version of $this->content.
TextPlainUnitTest::assertRaw in drupal/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
Asserts that a raw string appears in $this->content.
TextPlainUnitTest::assertText in drupal/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
Asserts that a text string appears in the text-only version of $this->content.

File

drupal/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php, line 150
Contains \Drupal\text\Tests\Formatter\TextPlainUnitTest.

Class

TextPlainUnitTest
Tests the text_plain field formatter.

Namespace

Drupal\text\Tests\Formatter

Code

protected function formatString($message, array $args) {
  array_walk($args, function (&$value) {

    // Export/dump the raw replacement token value.
    $value = var_export($value, TRUE);

    // Sanitize the value for output.
    $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');

    // Wrap the value in a PRE element if it contains newlines.
    if (strpos($value, "\n")) {
      $value = '<pre style="white-space: pre-wrap;">' . $value . '</pre>';
    }
  });
  return strtr($message, $args);
}