function TwigSandboxTest::testUrlSafeMethods

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php \Drupal\Tests\Core\Template\TwigSandboxTest::testUrlSafeMethods()
  2. 8.9.x core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php \Drupal\Tests\Core\Template\TwigSandboxTest::testUrlSafeMethods()
  3. 11.x 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 147

Class

TwigSandboxTest
Tests the twig sandbox policy.

Namespace

Drupal\Tests\Core\Template

Code

public function testUrlSafeMethods() : void {
  $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.');
}

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