function SafeMarkupTest::testFormat

Tests string formatting with SafeMarkup::format().

@dataProvider providerFormat @covers ::format @expectedDeprecation SafeMarkup::format() is scheduled for removal in Drupal 9.0.0. Use \Drupal\Component\Render\FormattableMarkup. See https://www.drupal.org/node/2549395.

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 127

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, (string) $result, $message);
    if ($expected_is_safe) {
        $this->assertInstanceOf(MarkupInterface::class, $result);
    }
    else {
        $this->assertNotInstanceOf(MarkupInterface::class, $result);
    }
}

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