public function SaveUploadFormTest::testCombinedErrorMessages in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/Functional/SaveUploadFormTest.php \Drupal\Tests\file\Functional\SaveUploadFormTest::testCombinedErrorMessages()
- 10 core/modules/file/tests/src/Functional/SaveUploadFormTest.php \Drupal\Tests\file\Functional\SaveUploadFormTest::testCombinedErrorMessages()
Tests that multiple validation errors are combined in one message.
File
- core/
modules/ file/ tests/ src/ Functional/ SaveUploadFormTest.php, line 500
Class
- SaveUploadFormTest
- Tests the _file_save_upload_from_form() function.
Namespace
Drupal\Tests\file\FunctionalCode
public function testCombinedErrorMessages() {
$textfile = current($this
->drupalGetTestFiles('text'));
$this
->assertFileExists($textfile->uri);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
// Can't use drupalPostForm() for set nonexistent fields.
$this
->drupalGet('file-test/save_upload_from_form_test');
$client = $this
->getSession()
->getDriver()
->getClient();
$submit_xpath = $this
->assertSession()
->buttonExists('Submit')
->getXpath();
$form = $client
->getCrawler()
->filterXPath($submit_xpath)
->form();
$edit = [
'is_image_file' => TRUE,
'extensions' => 'jpeg',
];
$edit += $form
->getPhpValues();
$files['files']['file_test_upload'][0] = $file_system
->realpath($this->phpfile->uri);
$files['files']['file_test_upload'][1] = $file_system
->realpath($textfile->uri);
$client
->request($form
->getMethod(), $form
->getUri(), $edit, $files);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.');
// Search for combined error message followed by a formatted list of messages.
$this
->assertRaw(t('One or more files could not be uploaded.') . '<div class="item-list">', 'Error message contains combined list of validation errors.');
}