function UnmanagedCopyTest::testNormal in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/File/UnmanagedCopyTest.php \Drupal\system\Tests\File\UnmanagedCopyTest::testNormal()
Copy a normal file.
File
- core/
modules/ system/ src/ Tests/ File/ UnmanagedCopyTest.php, line 22 - Contains \Drupal\system\Tests\File\UnmanagedCopyTest.
Class
- UnmanagedCopyTest
- Tests the unmanaged file copy function.
Namespace
Drupal\system\Tests\FileCode
function testNormal() {
// Create a file for testing
$uri = $this
->createUri();
// Copying to a new name.
$desired_filepath = 'public://' . $this
->randomMachineName();
$new_filepath = file_unmanaged_copy($uri, $desired_filepath, FILE_EXISTS_ERROR);
$this
->assertTrue($new_filepath, 'Copy was successful.');
$this
->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.');
$this
->assertTrue(file_exists($uri), 'Original file remains.');
$this
->assertTrue(file_exists($new_filepath), 'New file exists.');
$this
->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE));
// Copying with rename.
$desired_filepath = 'public://' . $this
->randomMachineName();
$this
->assertTrue(file_put_contents($desired_filepath, ' '), 'Created a file so a rename will have to happen.');
$newer_filepath = file_unmanaged_copy($uri, $desired_filepath, FILE_EXISTS_RENAME);
$this
->assertTrue($newer_filepath, 'Copy was successful.');
$this
->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.');
$this
->assertTrue(file_exists($uri), 'Original file remains.');
$this
->assertTrue(file_exists($newer_filepath), 'New file exists.');
$this
->assertFilePermissions($newer_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE));
// TODO: test copying to a directory (rather than full directory/file path)
// TODO: test copying normal files using normal paths (rather than only streams)
}