function SaveUploadFormTest::testCombinedErrorMessages

Same name and namespace in other branches
  1. 8.9.x core/modules/file/tests/src/Functional/SaveUploadFormTest.php \Drupal\Tests\file\Functional\SaveUploadFormTest::testCombinedErrorMessages()
  2. 10 core/modules/file/tests/src/Functional/SaveUploadFormTest.php \Drupal\Tests\file\Functional\SaveUploadFormTest::testCombinedErrorMessages()
  3. 11.x 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 549

Class

SaveUploadFormTest
Tests the <a href="/api/drupal/core%21modules%21file%21file.module/function/_file_save_upload_from_form/9" title="Saves form file uploads." class="local">_file_save_upload_from_form</a>() function.

Namespace

Drupal\Tests\file\Functional

Code

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 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($textfile->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.