function CopyTest::testNormal in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/CopyTest.php \Drupal\file\Tests\CopyTest::testNormal()
Test file copying in the normal, base case.
File
- core/
modules/ file/ src/ Tests/ CopyTest.php, line 21 - Contains \Drupal\file\Tests\CopyTest.
Class
- CopyTest
- Tests the file copy function.
Namespace
Drupal\file\TestsCode
function testNormal() {
$contents = $this
->randomMachineName(10);
$source = $this
->createFile(NULL, $contents);
$desired_uri = 'public://' . $this
->randomMachineName();
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_copy(clone $source, $desired_uri, FILE_EXISTS_ERROR);
// Check the return status and that the contents changed.
$this
->assertTrue($result, 'File copied successfully.');
$this
->assertEqual($contents, file_get_contents($result
->getFileUri()), 'Contents of file were copied correctly.');
// Check that the correct hooks were called.
$this
->assertFileHooksCalled(array(
'copy',
'insert',
));
$this
->assertDifferentFile($source, $result);
$this
->assertEqual($result
->getFileUri(), $desired_uri, 'The copied file entity has the desired filepath.');
$this
->assertTrue(file_exists($source
->getFileUri()), 'The original file still exists.');
$this
->assertTrue(file_exists($result
->getFileUri()), 'The copied file exists.');
// Reload the file from the database and check that the changes were
// actually saved.
$this
->assertFileUnchanged($result, File::load($result
->id()));
}