You are here

function UrlRewritingTest::testRelativeFileURL in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/File/UrlRewritingTest.php \Drupal\system\Tests\File\UrlRewritingTest::testRelativeFileURL()

Test file_url_transform_relative().

File

core/modules/system/src/Tests/File/UrlRewritingTest.php, line 102
Contains \Drupal\system\Tests\File\UrlRewritingTest.

Class

UrlRewritingTest
Tests for file URL rewriting.

Namespace

Drupal\system\Tests\File

Code

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
    ->assertIdentical(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
    ->assertIdentical(base_path() . $public_directory_path . '/' . rawurlencode(drupal_basename($uri)), file_url_transform_relative($url));
}