function SaveUploadTest::testRequired
Same name in other branches
- 10 core/modules/file/tests/src/Functional/SaveUploadTest.php \Drupal\Tests\file\Functional\SaveUploadTest::testRequired()
- 11.x core/modules/file/tests/src/Functional/SaveUploadTest.php \Drupal\Tests\file\Functional\SaveUploadTest::testRequired()
Tests the file_save_upload() function when the field is required.
File
-
core/
modules/ file/ tests/ src/ Functional/ SaveUploadTest.php, line 738
Class
- SaveUploadTest
- Tests the file_save_upload() function.
Namespace
Drupal\Tests\file\FunctionalCode
public function testRequired() {
// Reset the hook counters to get rid of the 'load' we just called.
file_test_reset();
// Confirm the field is required.
$this->drupalGet('file-test/upload_required');
$this->submitForm([], 'Submit');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->responseContains('field is required');
// Confirm that uploading another file works.
$image = current($this->drupalGetTestFiles('image'));
$edit = [
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($image->uri),
];
$this->drupalGet('file-test/upload_required');
$this->submitForm($edit, 'Submit');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->responseContains('You WIN!');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.