You are here

public function SafeMarkupTest::testFormat 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::testFormat()

Tests string formatting with SafeMarkup::format().

@dataProvider providerFormat @covers ::format

Parameters

string $string: The string to run through SafeMarkup::format().

string[] $args: The arguments to pass into SafeMarkup::format().

string $expected: The expected result from calling the function.

string $message: The message to display as output to the test.

bool $expected_is_safe: Whether the result is expected to be safe for HTML display.

File

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

Class

SafeMarkupTest
Tests marking strings as safe.

Namespace

Drupal\Tests\Component\Utility

Code

public function testFormat($string, array $args, $expected, $message, $expected_is_safe) {
  UrlHelper::setAllowedProtocols([
    'http',
    'https',
    'mailto',
  ]);
  $result = SafeMarkup::format($string, $args);
  $this
    ->assertEquals($expected, $result, $message);
  $this
    ->assertEquals($expected_is_safe, SafeMarkup::isSafe($result), 'SafeMarkup::format correctly sets the result as safe or not safe.');
  foreach ($args as $arg) {
    $this
      ->assertSame($arg instanceof SafeMarkupTestMarkup, SafeMarkup::isSafe($arg));
  }
}