function FormattableMarkupTest::testToString

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testToString()
  2. 8.9.x core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testToString()
  3. 10 core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testToString()

@covers ::__toString @covers ::jsonSerialize

File

core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php, line 39

Class

FormattableMarkupTest
Tests the TranslatableMarkup class.

Namespace

Drupal\Tests\Component\Render

Code

public function testToString() : void {
    $string = 'Can I have a @replacement';
    $formattable_string = new FormattableMarkup($string, [
        '@replacement' => 'kitten',
    ]);
    $text = (string) $formattable_string;
    $this->assertEquals('Can I have a kitten', $text);
    $text = $formattable_string->jsonSerialize();
    $this->assertEquals('Can I have a kitten', $text);
}

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