function FileUrlGeneratorTest::testGenerateURI

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testGenerateURI()
  2. 10 core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testGenerateURI()

@covers ::generate

@dataProvider providerGenerateURI

File

core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php, line 185

Class

FileUrlGeneratorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21File%21FileUrlGenerator.php/class/FileUrlGenerator/11.x" title="Default implementation for the file URL generator service." class="local">\Drupal\Core\File\FileUrlGenerator</a>

Namespace

Drupal\KernelTests\Core\File

Code

public function testGenerateURI($filepath, $expected) : void {
    // Disable file_test.module's hook_file_url_alter() implementation.
    \Drupal::state()->set('file_test.hook_file_url_alter', NULL);
    // Create a mock Request for transformRelative().
    $request = Request::create($GLOBALS['base_url']);
    $request->setSession(new Session(new MockArraySessionStorage()));
    $this->container
        ->get('request_stack')
        ->push($request);
    \Drupal::setContainer($this->container);
    // No schema file.
    $url = $this->fileUrlGenerator
        ->generate($filepath);
    $this->assertEquals($expected, $url->toUriString());
}

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