function UrlRewritingTest::testPublicManagedFileURL in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/File/UrlRewritingTest.php \Drupal\system\Tests\File\UrlRewritingTest::testPublicManagedFileURL()
Tests the rewriting of public managed file URLs by hook_file_url_alter().
File
- core/
modules/ system/ src/ Tests/ File/ UrlRewritingTest.php, line 76 - Contains \Drupal\system\Tests\File\UrlRewritingTest.
Class
- UrlRewritingTest
- Tests for file URL rewriting.
Namespace
Drupal\system\Tests\FileCode
function testPublicManagedFileURL() {
// Test generating an URL to a managed file.
// Test alteration of file URLs to use a CDN.
\Drupal::state()
->set('file_test.hook_file_url_alter', 'cdn');
$uri = $this
->createUri();
$url = file_create_url($uri);
$public_directory_path = \Drupal::service('stream_wrapper_manager')
->getViaScheme('public')
->getDirectoryPath();
$this
->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a CDN URL for a created file.');
// Test alteration of file URLs to use root-relative URLs.
\Drupal::state()
->set('file_test.hook_file_url_alter', 'root-relative');
$uri = $this
->createUri();
$url = file_create_url($uri);
$this
->assertEqual(base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a root-relative URL for a created file.');
// Test alteration of file URLs to use a protocol-relative URLs.
\Drupal::state()
->set('file_test.hook_file_url_alter', 'protocol-relative');
$uri = $this
->createUri();
$url = file_create_url($uri);
$this
->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a protocol-relative URL for a created file.');
}