/**
* Tests the file paths of newly created files.
*/
public function testFileCreateNewFilepath() { // First we test against an imaginary file that does not exist in a
// directory.
$basename = 'xyz.txt';
$directory = 'core/misc';
$original =
$directory . '/' .
$basename;
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::
service('file_system'
);
$path =
$file_system->
createFilename($basename,
$directory);
$this->
assertEquals($original,
$path,
new FormattableMarkup('New filepath %new equals %original.',
['%new' =>
$path, '%original' =>
$original]));
// Then we test against a file that already exists within that directory.
$basename = 'druplicon.png';
$original =
$directory . '/' .
$basename;
$expected =
$directory . '/druplicon_0.png';
$path =
$file_system->
createFilename($basename,
$directory);
$this->
assertEquals($expected,
$path,
new FormattableMarkup('Creating a new filepath from %original equals %new (expected %expected).',
['%new' =>
$path, '%original' =>
$original, '%expected' =>
$expected]));
// @TODO: Finally we copy a file into a directory several times, to ensure a properly iterating filename suffix.
}