public function FileMoveTest::testOverwriteSelf in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testOverwriteSelf()
- 9 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 63
Class
- FileMoveTest
- Tests the unmanaged file move function.
Namespace
Drupal\KernelTests\Core\FileCode
public function testOverwriteSelf() {
// 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, FileSystemInterface::EXISTS_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, FileSystemInterface::EXISTS_RENAME);
$this
->assertNotFalse($new_filepath, 'Moving onto itself with renaming works.');
$this
->assertFileDoesNotExist($uri);
$this
->assertFileExists($new_filepath);
}