$this->fileUrlGenerator =
$this->container->
get('file_url_generator'
);
// Clear out any hook calls.
file_test_reset();
} /**
* Tests the public file transfer system.
*/
public function testPublicFileTransfer() { // Test generating a URL to a created file.
$file =
$this->
createFile();
$url =
$this->fileUrlGenerator->
generateAbsoluteString($file->
getFileUri());
// URLs can't contain characters outside the ASCII set so $filename has to be
// encoded.
$filename =
$GLOBALS['base_url'
] . '/' . \Drupal::
service('stream_wrapper_manager'
)->
getViaScheme('public'
)->
getDirectoryPath() . '/' .
rawurlencode($file->
getFilename());
$this->
assertEquals($filename,
$url, 'Correctly generated a URL for a created file.'
);
$http_client =
$this->
getHttpClient();
$response =
$http_client->
head($url);
$this->
assertEquals(200,
$response->
getStatusCode(), 'Confirmed that the generated URL is correct by downloading the created file.'
);
// Test generating a 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).
$filepath = 'core/assets/vendor/jquery/jquery.min.js';