function FileUrlGeneratorTest::testRelativeFileURL
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testRelativeFileURL()
- 10 core/tests/Drupal/KernelTests/Core/File/FileUrlGeneratorTest.php \Drupal\KernelTests\Core\File\FileUrlGeneratorTest::testRelativeFileURL()
Tests generate absolute string with relative URL.
@covers ::generateAbsoluteString
File
-
core/
tests/ Drupal/ KernelTests/ Core/ File/ FileUrlGeneratorTest.php, line 155
Class
- FileUrlGeneratorTest
- @coversDefaultClass \Drupal\Core\File\FileUrlGenerator
Namespace
Drupal\KernelTests\Core\FileCode
public function testRelativeFileURL() : 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);
// Shipped file.
$filepath = 'core/assets/vendor/jquery/jquery.min.js';
$url = $this->fileUrlGenerator
->generateAbsoluteString($filepath);
$this->assertSame(base_path() . $filepath, $this->fileUrlGenerator
->transformRelative($url));
// Managed file.
$uri = $this->createUri();
$url = $this->fileUrlGenerator
->generateAbsoluteString($uri);
$public_directory_path = \Drupal::service('stream_wrapper_manager')->getViaScheme('public')
->getDirectoryPath();
$this->assertSame(base_path() . $public_directory_path . '/' . rawurlencode(\Drupal::service('file_system')->basename($uri)), $this->fileUrlGenerator
->transformRelative($url));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.