function DirectoryTest::testFileCreateNewFilepath in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/File/DirectoryTest.php \Drupal\system\Tests\File\DirectoryTest::testFileCreateNewFilepath()
This will take a directory and path, and find a valid filepath that is not taken by another file.
File
- core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php, line 106 - Contains \Drupal\system\Tests\File\DirectoryTest.
Class
- DirectoryTest
- Tests operations dealing with directories.
Namespace
Drupal\system\Tests\FileCode
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;
$path = file_create_filename($basename, $directory);
$this
->assertEqual($path, $original, format_string('New filepath %new equals %original.', array(
'%new' => $path,
'%original' => $original,
)), 'File');
// 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_create_filename($basename, $directory);
$this
->assertEqual($path, $expected, format_string('Creating a new filepath from %original equals %new (expected %expected).', array(
'%new' => $path,
'%original' => $original,
'%expected' => $expected,
)), 'File');
// @TODO: Finally we copy a file into a directory several times, to ensure a properly iterating filename suffix.
}