You are here

public function TwigExtensionTest::testFileUrl in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testFileUrl()

Tests the file_url filter.

File

core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php, line 182

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testFileUrl() {
  $this->fileUrlGenerator
    ->expects($this
    ->once())
    ->method('generateString')
    ->with('public://picture.jpg')
    ->willReturn('sites/default/files/picture.jpg');
  $loader = new StringLoader();
  $twig = new Environment($loader);
  $twig
    ->addExtension($this->systemUnderTest);
  $result = $twig
    ->render('{{ file_url(file) }}', [
    'file' => 'public://picture.jpg',
  ]);
  $this
    ->assertEquals('sites/default/files/picture.jpg', $result);
}