// Public files should not be served by Drupal, so their URLs should not be
// routed through Drupal, whereas private files should be served by Drupal,
// so they need to be. The difference is most apparent when $script_path
// is not empty (i.e., when not using clean URLs).
$clean_url_settings =
[ 'clean' => '',
'unclean' => 'index.php/',
];
$public_directory_path = \Drupal::
service('stream_wrapper_manager'
)->
getViaScheme('public'
)->
getDirectoryPath();
foreach ($clean_url_settings as $clean_url_setting =>
$script_path) { $clean_urls =
$clean_url_setting == 'clean';
$request =
$this->
prepareRequestForGenerator($clean_urls);
$base_path =
$request->
getSchemeAndHttpHost() .
$request->
getBasePath();
$this->
checkUrl('public', '',
$basename,
$base_path . '/' .
$public_directory_path . '/' .
$basename_encoded);
$this->
checkUrl('private', '',
$basename,
$base_path . '/' .
$script_path . 'system/files/' .
$basename_encoded);
} $this->
assertEquals('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==',
$this->fileUrlGenerator->
generateString('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', FALSE
));
} /**
* Download a file from the URL generated by generateString().
*
* Create a file with the specified scheme, directory and filename; check that
* the URL generated by FileUrlGeneratorInterface::generateString() for the
* specified file equals the specified URL; fetch the URL and then compare the
* contents to the file.
*
* @param string $scheme
* A scheme, e.g. "public".
* @param string $directory
* A directory, possibly "".
* @param string $filename
* A filename.
* @param string $expected_url
* The expected URL.
*/