You are here

public function TwigSandboxTest::testUrlSafeMethods in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php \Drupal\Tests\Core\Template\TwigSandboxTest::testUrlSafeMethods()

Tests that safe methods inside Url objects can be called.

File

core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php, line 149
Contains \Drupal\Tests\Core\Template\TwigSandboxTest.

Class

TwigSandboxTest
Tests the twig sandbox policy.

Namespace

Drupal\Tests\Core\Template

Code

public function testUrlSafeMethods() {
  $url = $this
    ->getMockBuilder('Drupal\\Core\\Url')
    ->disableOriginalConstructor()
    ->getMock();
  $url
    ->expects($this
    ->once())
    ->method('toString')
    ->willReturn('http://kittens.cat/are/cute');
  $result = $this->twig
    ->render('{{ url.toString }}', [
    'url' => $url,
  ]);
  $this
    ->assertEquals('http://kittens.cat/are/cute', $result, 'Sandbox policy allows toString() to be called.');
}