function EntityReferenceFileUploadTest::testFileUpload

Same name in other branches
  1. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFileUploadTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFileUploadTest::testFileUpload()
  2. 8.9.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFileUploadTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFileUploadTest::testFileUpload()
  3. 11.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFileUploadTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFileUploadTest::testFileUpload()

Tests that the autocomplete input element does not cause ajax fatal.

File

core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFileUploadTest.php, line 131

Class

EntityReferenceFileUploadTest
Tests an autocomplete widget with file upload.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

public function testFileUpload() : void {
    $user1 = $this->drupalCreateUser([
        'access content',
        "create {$this->referencingType} content",
    ]);
    $this->drupalLogin($user1);
    $test_file = current($this->getTestFiles('text'));
    $edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
    $this->drupalGet('node/add/' . $this->referencingType);
    $this->submitForm($edit, 'Upload');
    $this->assertSession()
        ->statusCodeEquals(200);
    $edit = [
        'title[0][value]' => $this->randomMachineName(),
        'test_field[0][target_id]' => $this->nodeId,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.