You are here

public function FileFieldSourcesTestBase::uploadFileByClipboardSource in FileField Sources 8

Upload file by 'Clipboard' source.

Parameters

string $uri: File uri.

string $filename: File name.

int $delta: Delta in multiple values field.

3 calls to FileFieldSourcesTestBase::uploadFileByClipboardSource()
ClipboardSourceTest::testClipboardSourceEnabled in tests/src/Functional/ClipboardSourceTest.php
Tests clipboard source enabled.
EmptyValuesTest::testAllSourcesEnabled in tests/src/Functional/EmptyValuesTest.php
Tests all sources enabled.
MultipleValuesTest::uploadFiles in tests/src/Functional/MultipleValuesTest.php
Upload files.

File

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

Class

FileFieldSourcesTestBase
Base class for File Field Sources test cases.

Namespace

Drupal\Tests\filefield_sources\Functional

Code

public function uploadFileByClipboardSource($uri = '', $filename = '', $delta = 0) {
  $prefix = $this->fieldName . '[' . $delta . '][filefield_clipboard]';
  $file_content = $uri ? 'data:text/plain;base64,' . base64_encode(file_get_contents($uri)) : '';

  // Can't be used drupalPostForm here because the fields are of type hidden
  // and drupalPostForm don't see those, let's set the values manually.
  $this
    ->getSession()
    ->getPage()
    ->find('css', 'input[name="' . $prefix . '[filename]"]')
    ->setValue($filename);
  $this
    ->getSession()
    ->getPage()
    ->find('css', 'input[name="' . $prefix . '[contents]"]')
    ->setValue($file_content);
  $this
    ->getSession()
    ->getPage()
    ->pressButton($this->fieldName . '_' . $delta . '_clipboard_upload_button');
  if ($filename) {
    $this
      ->assertFileUploaded($filename, $delta);
  }
  else {
    $this
      ->assertFileNotUploaded($delta);
  }
}