public function UrlRewritingTest::testRelativeFileURL in Drupal 8
Test file_url_transform_relative().
File
- core/
tests/ Drupal/ KernelTests/ Core/ File/ UrlRewritingTest.php, line 99
Class
- UrlRewritingTest
- Tests for file URL rewriting.
Namespace
Drupal\KernelTests\Core\FileCode
public function testRelativeFileURL() {
// 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 file_url_transform_relative().
$request = Request::create($GLOBALS['base_url']);
$this->container
->get('request_stack')
->push($request);
\Drupal::setContainer($this->container);
// Shipped file.
$filepath = 'core/assets/vendor/jquery/jquery.min.js';
$url = file_create_url($filepath);
$this
->assertSame(base_path() . $filepath, file_url_transform_relative($url));
// Managed file.
$uri = $this
->createUri();
$url = file_create_url($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)), file_url_transform_relative($url));
}