function TwigSandboxTest::testUrlSafeMethods

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

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.');
}

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