function FileUrlGeneratorTest::testGenerateURIWithSchema

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testGenerateURIWithSchema()
  2. 11.x core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testGenerateURIWithSchema()

@covers ::generate

File

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

Class

FileUrlGeneratorTest
@coversDefaultClass \Drupal\Core\File\FileUrlGenerator

Namespace

Drupal\KernelTests\Core\File

Code

public function testGenerateURIWithSchema() : 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);
    $public_directory_path = \Drupal::service('stream_wrapper_manager')->getViaScheme('public')
        ->getDirectoryPath();
    $url = $this->fileUrlGenerator
        ->generate('public://path/to/file.png');
    $this->assertEquals('base:/' . $public_directory_path . '/path/to/file.png', $url->getUri());
}

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