function EntityReferenceFileUploadTest::testFileUpload

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFileUploadTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFileUploadTest::testFileUpload()
  2. 10 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 123

Class

EntityReferenceFileUploadTest
Tests an autocomplete widget with file upload.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

public function testFileUpload() {
    $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->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload');
    $this->assertSession()
        ->statusCodeEquals(200);
    $edit = [
        'title[0][value]' => $this->randomMachineName(),
        'test_field[0][target_id]' => $this->nodeId,
    ];
    $this->drupalPostForm(NULL, $edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
}

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