You are here

public function SafeMarkupTest::testUnexpectedFormat in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php \Drupal\Tests\Component\Utility\SafeMarkupTest::testUnexpectedFormat()

String formatting with SafeMarkup::format() and an unsupported placeholder.

When you call SafeMarkup::format() with an unsupported placeholder, an InvalidArgumentException should be thrown.

File

core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php, line 199
Contains \Drupal\Tests\Component\Utility\SafeMarkupTest.

Class

SafeMarkupTest
Tests marking strings as safe.

Namespace

Drupal\Tests\Component\Utility

Code

public function testUnexpectedFormat() {

  // We set a custom error handler because of https://github.com/sebastianbergmann/phpunit/issues/487
  set_error_handler([
    $this,
    'errorHandler',
  ]);

  // We want this to trigger an error.
  $error = SafeMarkup::format('Broken placeholder: ~placeholder', [
    '~placeholder' => 'broken',
  ])
    ->__toString();
  restore_error_handler();
  $this
    ->assertEquals(E_USER_ERROR, $this->lastErrorNumber);
  $this
    ->assertEquals('Invalid placeholder: ~placeholder', $this->lastErrorMessage);
}