function MoveTest::testExistingError in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/MoveTest.php \Drupal\file\Tests\MoveTest::testExistingError()
Test that moving onto an existing file fails when FILE_EXISTS_ERROR is specified.
File
- core/
modules/ file/ src/ Tests/ MoveTest.php, line 141 - Contains \Drupal\file\Tests\MoveTest.
Class
- MoveTest
- Tests the file move function.
Namespace
Drupal\file\TestsCode
function testExistingError() {
$contents = $this
->randomMachineName(10);
$source = $this
->createFile();
$target = $this
->createFile(NULL, $contents);
$this
->assertDifferentFile($source, $target);
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_move(clone $source, $target
->getFileUri(), FILE_EXISTS_ERROR);
// Check the return status and that the contents did not change.
$this
->assertFalse($result, 'File move failed.');
$this
->assertTrue(file_exists($source
->getFileUri()));
$this
->assertEqual($contents, file_get_contents($target
->getFileUri()), 'Contents of file were not altered.');
// Check that no hooks were called while failing.
$this
->assertFileHooksCalled(array());
// Load the file from the database and make sure it is identical to what
// was returned.
$this
->assertFileUnchanged($source, File::load($source
->id()));
$this
->assertFileUnchanged($target, File::load($target
->id()));
}