function FileMoveTest::testExistingReplace in SimpleTest 7
Test replacement when moving onto a file that already exists.
File
- tests/
file.test, line 1333 - This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.
Class
- FileMoveTest
- Move related tests
Code
function testExistingReplace() {
// Setup a file to overwrite.
$contents = $this
->randomName(10);
$source = $this
->createFile(NULL, $contents);
$target = $this
->createFile();
$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->uri, FILE_EXISTS_REPLACE);
// Look at the results.
$this
->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were overwritten.'));
$this
->assertFalse(file_exists($source->uri));
$this
->assertTrue($result, t('File moved sucessfully.'));
// Check that the correct hooks were called.
$this
->assertFileHooksCalled(array(
'move',
'update',
'delete',
'references',
'load',
));
// Reload the file from the database and check that the changes were
// actually saved.
$loaded_result = file_load($result->fid, TRUE);
$this
->assertFileUnchanged($result, $loaded_result);
// Check that target was re-used.
$this
->assertSameFile($target, $loaded_result);
// Source and result should be totally different.
$this
->assertDifferentFile($source, $loaded_result);
}