5 * Definition of Drupal\filefield_sources\Tests\MultipleValuesTest.
8 namespace Drupal\filefield_sources\Tests;
10 use Drupal\Core\Field\FieldStorageDefinitionInterface;
13 * Tests multiple sources on multiple values field.
15 * @group filefield_sources
17 class MultipleValuesTest extends FileFieldSourcesTestBase {
24 public static $modules = array('imce');
27 * Sets up for multiple values test case.
29 protected function setUp() {
34 $this->permanent_file_entity_1 = $this->createPermanentFileEntity();
35 $this->permanent_file_entity_2 = $this->createPermanentFileEntity();
36 $this->temporary_file_entity_1 = $this->createTemporaryFileEntity();
37 $this->temporary_file_entity_2 = $this->createTemporaryFileEntity();
39 $path = file_default_scheme() . '://' . FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH . '/';
40 $this->temporary_file = $this->createTemporaryFile($path);
42 // Change allowed number of values.
43 $this->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/fields/node.' . $this->typeName . '.' . $this->fieldName . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
45 $this->enableSources(array(
56 * Tests uploading then removing files.
58 public function testUploadThenRemoveFiles() {
61 // Remove all uploaded files.
62 $this->removeFile($this->temporary_file_entity_2->getFilename(), 4);
63 $this->removeFile('INSTALL.txt', 0);
64 $this->removeFile($this->temporary_file_entity_1->getFilename(), 1);
65 $this->removeFile($this->temporary_file->filename, 1);
66 $this->removeFile($this->permanent_file_entity_1->getFilename(), 0);
67 $this->removeFile($this->permanent_file_entity_2->getFilename(), 0);
69 // Ensure all files have been removed.
70 $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'All files have been removed.');
74 * Tests uploading files and saving node.
76 public function testUploadFilesThenSaveNode() {
79 $this->drupalPostForm(NULL, array('title[0][value]' => $this->randomMachineName()), t('Save and publish'));
81 // Ensure all files are saved to node.
82 $this->assertLink('INSTALL.txt');
83 $this->assertLink($this->permanent_file_entity_1->getFilename());
84 $this->assertLink($this->permanent_file_entity_2->getFilename());
85 $this->assertLink($this->temporary_file_entity_1->getFilename());
86 $this->assertLink($this->temporary_file_entity_2->getFilename());
87 $this->assertLink($this->temporary_file->filename);
94 * Number of files uploaded.
96 protected function uploadFiles() {
99 // Ensure no files has been uploaded.
100 $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'There are no file have been uploaded.');
102 // Upload a file by 'Remote' source.
103 $this->uploadFileByRemoteSource($GLOBALS['base_url'] . '/core/INSTALL.txt', 'INSTALL.txt', $uploaded_files);
106 // Upload a file by 'Reference' source.
107 $this->uploadFileByReferenceSource($this->permanent_file_entity_1->id(), $this->permanent_file_entity_1->getFilename(), $uploaded_files);
110 // Upload a file by 'Clipboard' source.
111 $this->uploadFileByClipboardSource($this->temporary_file_entity_1->getFileUri(), $this->temporary_file_entity_1->getFileName(), $uploaded_files);
114 // Upload a file by 'Attach' source.
115 $this->uploadFileByAttachSource($this->temporary_file->uri, $this->temporary_file->filename, $uploaded_files);
118 // Upload a file by 'Upload' source.
119 $this->uploadFileByUploadSource($this->temporary_file_entity_2->getFileUri(), $this->temporary_file_entity_2->getFilename(), $uploaded_files, TRUE);
122 // Upload a file by 'Imce' source.
123 $this->uploadFileByImceSource($this->permanent_file_entity_2->getFileUri(), $this->permanent_file_entity_2->getFileName(), $uploaded_files);
126 // Ensure files have been uploaded.
127 $remove_buttons = $this->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]');
128 $this->assertEqual(count($remove_buttons), $uploaded_files, "There are $uploaded_files files have been uploaded.");
130 return $uploaded_files;