public function TwigSandboxTest::testUrlSafeMethods in Drupal 8
Same name and namespace in other branches
- 9 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 146  - Contains \Drupal\Tests\Core\Template\TwigSandboxTest.
 
Class
- TwigSandboxTest
 - Tests the twig sandbox policy.
 
Namespace
Drupal\Tests\Core\TemplateCode
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($result, 'http://kittens.cat/are/cute', 'Sandbox policy allows toString() to be called.');
}