function SaveUploadFormTest::testCombinedErrorMessages
Tests that multiple validation errors are combined in one message.
File
- 
              core/modules/ file/ tests/ src/ Functional/ SaveUploadFormTest.php, line 550 
Class
- SaveUploadFormTest
- Tests the _file_save_upload_from_form() function.
Namespace
Drupal\Tests\file\FunctionalCode
public function testCombinedErrorMessages() : void {
  $text_file = current($this->drupalGetTestFiles('text'));
  $this->assertFileExists($text_file->uri);
  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  // Can't use submitForm() 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($text_file->uri);
  $client->request($form->getMethod(), $form->getUri(), $edit, $files);
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains("Epic upload FAIL!");
  // Search for combined error message followed by a formatted list of messages.
  $this->assertSession()
    ->responseContains('One or more files could not be uploaded.<ul>');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
