function UrlRewritingTest::testShippedFileURL

Test the generating of rewritten shipped file URLs.

File

drupal/core/modules/system/lib/Drupal/system/Tests/File/UrlRewritingTest.php, line 33
Definition of Drupal\system\Tests\File\UrlRewritingTest.

Class

UrlRewritingTest
Tests for file URL rewriting.

Namespace

Drupal\system\Tests\File

Code

function testShippedFileURL() {

  // Test generating an URL to a shipped file (i.e. a file that is part of
  // Drupal core, a module or a theme, for example a JavaScript file).
  // Test alteration of file URLs to use a CDN.
  state()
    ->set('file_test.hook_file_url_alter', 'cdn');
  $filepath = 'core/misc/jquery.js';
  $url = file_create_url($filepath);
  $this
    ->assertEqual(FILE_URL_TEST_CDN_1 . '/' . $filepath, $url, 'Correctly generated a CDN URL for a shipped file.');
  $filepath = 'core/misc/favicon.ico';
  $url = file_create_url($filepath);
  $this
    ->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $filepath, $url, 'Correctly generated a CDN URL for a shipped file.');

  // Test alteration of file URLs to use root-relative URLs.
  state()
    ->set('file_test.hook_file_url_alter', 'root-relative');
  $filepath = 'core/misc/jquery.js';
  $url = file_create_url($filepath);
  $this
    ->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
  $filepath = 'core/misc/favicon.ico';
  $url = file_create_url($filepath);
  $this
    ->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');

  // Test alteration of file URLs to use protocol-relative URLs.
  state()
    ->set('file_test.hook_file_url_alter', 'protocol-relative');
  $filepath = 'core/misc/jquery.js';
  $url = file_create_url($filepath);
  $this
    ->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
  $filepath = 'core/misc/favicon.ico';
  $url = file_create_url($filepath);
  $this
    ->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
}