You are here

public function FileFieldSourcesTestBase::uploadFileByUploadSource in FileField Sources 8

Upload file by 'Upload' source.

Parameters

string $uri: File uri.

string $filename: File name.

int $delta: Delta in multiple values field.

3 calls to FileFieldSourcesTestBase::uploadFileByUploadSource()
EmptyValuesTest::testAllSourcesEnabled in tests/src/Functional/EmptyValuesTest.php
Tests all sources enabled.
MultipleValuesTest::uploadFiles in tests/src/Functional/MultipleValuesTest.php
Upload files.
UploadSourceTest::assertUploadSourceWorkProperly in tests/src/Functional/UploadSourceTest.php
Tests upload source still working properly.

File

tests/src/Functional/FileFieldSourcesTestBase.php, line 401

Class

FileFieldSourcesTestBase
Base class for File Field Sources test cases.

Namespace

Drupal\Tests\filefield_sources\Functional

Code

public function uploadFileByUploadSource($uri = '', $filename = '', $delta = 0, $multiple = FALSE) {
  $name = 'files[' . $this->fieldName . '_' . $delta . ']';
  if ($multiple) {
    $name .= '[]';
  }
  $edit = [
    $name => $uri ? \Drupal::getContainer()
      ->get('file_system')
      ->realPath($uri) : '',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this->fieldName . '_' . $delta . '_upload_button');
  if ($filename) {
    $this
      ->assertFileUploaded($filename, $delta);
  }
  else {
    $this
      ->assertFileNotUploaded($delta);
  }
}