public function AttachSourceTest::testCopyFileFromAbsolutePath in FileField Sources 8
Tests copy file from absolute path.
Copy file from 'sites/default/files/custom_file_attach' to 'public://'.
File
- tests/
src/ Functional/ AttachSourceTest.php, line 144
Class
- AttachSourceTest
- Tests the attach source.
Namespace
Drupal\Tests\filefield_sources\FunctionalCode
public function testCopyFileFromAbsolutePath() {
$uri_scheme = $this
->getFieldSetting('uri_scheme');
$path = $this
->getCustomAttachPath();
// Create test file.
$file = $this
->createTemporaryFile($path);
$dest_uri = $this
->getDestinationUri($file, $uri_scheme);
// Change settings.
$this
->updateFilefieldSourcesSettings('source_attach', 'path', $path);
$this
->updateFilefieldSourcesSettings('source_attach', 'absolute', FILEFIELD_SOURCE_ATTACH_ABSOLUTE);
$this
->updateFilefieldSourcesSettings('source_attach', 'attach_mode', FILEFIELD_SOURCE_ATTACH_MODE_COPY);
$this
->enableSources([
'attach' => TRUE,
]);
$this
->assertCanAttachFile($file);
// Upload a file.
$this
->uploadFileByAttachSource($file->uri, $file->filename, 0);
// We can only attach one file on single value field.
$this
->assertNoFieldByXPath('//input[@type="submit"]', t('Attach'), 'After uploading a file, "Attach" button is no longer displayed.');
// Ensure file is copied.
$this
->assertTrue(is_file($file->uri), 'Source file still exists.');
$this
->assertTrue(is_file($dest_uri), 'Destination file has been created.');
$this
->removeFile($file->filename, 0);
$this
->assertCanAttachFile($file);
}