/**
* Tests the rewriting of public managed file URLs by hook_file_url_alter().
*
* @covers ::generateAbsoluteString
*/
public function testPublicManagedFileURL() { // Test generating a 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 =
$this->fileUrlGenerator->
generateAbsoluteString($uri);
$public_directory_path = \Drupal::
service('stream_wrapper_manager'
) ->
getViaScheme('public'
) ->
getDirectoryPath();
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::
service('file_system'
);
$this->
assertEquals(FILE_URL_TEST_CDN_2 . '/' .
$public_directory_path . '/' .
$file_system->
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();