function FileMoveTest::testOverwriteSelf
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testOverwriteSelf()
- 8.9.x core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testOverwriteSelf()
- 10 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testOverwriteSelf()
Try to move a file onto itself.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ File/ FileMoveTest.php, line 65
Class
- FileMoveTest
- Tests the unmanaged file move function.
Namespace
Drupal\KernelTests\Core\FileCode
public function testOverwriteSelf() : void {
// Create a file for testing.
$uri = $this->createUri();
// Move the file onto itself without renaming shouldn't make changes.
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$this->expectException(FileException::class);
$new_filepath = $file_system->move($uri, $uri, FileExists::Replace);
$this->assertFalse($new_filepath, 'Moving onto itself without renaming fails.');
$this->assertFileExists($uri);
// Move the file onto itself with renaming will result in a new filename.
$new_filepath = $file_system->move($uri, $uri, FileExists::Rename);
$this->assertNotFalse($new_filepath, 'Moving onto itself with renaming works.');
$this->assertFileDoesNotExist($uri);
$this->assertFileExists($new_filepath);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.