public function FileFieldWidgetTest::testUploadingMoreFilesThenAllowed in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldWidgetTest::testUploadingMoreFilesThenAllowed()
Tests uploading more files then allowed at once.
File
- core/
modules/ file/ tests/ src/ FunctionalJavascript/ FileFieldWidgetTest.php, line 189
Class
- FileFieldWidgetTest
- Tests the file field widget, single and multi-valued, using AJAX upload.
Namespace
Drupal\Tests\file\FunctionalJavascriptCode
public function testUploadingMoreFilesThenAllowed() {
$type_name = 'article';
$field_name = 'test_file_field_1';
$cardinality = 2;
$this
->createFileField($field_name, 'node', $type_name, [
'cardinality' => $cardinality,
]);
$web_driver = $this
->getSession()
->getDriver();
$file_system = \Drupal::service('file_system');
$files = array_slice($this
->getTestFiles('text'), 0, 3);
$real_paths = [];
foreach ($files as $file) {
$real_paths[] = $file_system
->realpath($file->uri);
}
$remote_paths = [];
foreach ($real_paths as $path) {
$remote_paths[] = $web_driver
->uploadFileAndGetRemoteFilePath($path);
}
// Tests that uploading multiple remote files works with remote path.
$this
->drupalGet("node/add/{$type_name}");
$multiple_field = $this
->getSession()
->getPage()
->findField('files[test_file_field_1_0][]');
$multiple_field
->setValue(implode("\n", $remote_paths));
$this
->assertSession()
->assertWaitOnAjaxRequest();
$args = [
'%field' => $field_name,
'@max' => $cardinality,
'@count' => 3,
'%list' => 'text-2.txt',
];
$this
->assertRaw(t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args));
}