You are here

protected function MultipleValuesTest::uploadFiles in FileField Sources 8

Upload files.

Return value

int Number of files uploaded.

2 calls to MultipleValuesTest::uploadFiles()
MultipleValuesTest::testUploadFilesThenSaveNode in tests/src/Functional/MultipleValuesTest.php
Tests uploading files and saving node.
MultipleValuesTest::testUploadThenRemoveFiles in tests/src/Functional/MultipleValuesTest.php
Tests uploading then removing files.

File

tests/src/Functional/MultipleValuesTest.php, line 126

Class

MultipleValuesTest
Tests multiple sources on multiple values field.

Namespace

Drupal\Tests\filefield_sources\Functional

Code

protected function uploadFiles() {
  $uploaded_files = 0;

  // Ensure no files has been uploaded.
  $this
    ->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'There are no file have been uploaded.');

  // Upload a file by 'Remote' source.
  $this
    ->uploadFileByRemoteSource($GLOBALS['base_url'] . '/core/INSTALL.txt', 'INSTALL.txt', $uploaded_files);
  $uploaded_files++;

  // Upload a file by 'Reference' source.
  $this
    ->uploadFileByReferenceSource($this->permanentFileEntity1
    ->id(), $this->permanentFileEntity1
    ->getFilename(), $uploaded_files);
  $uploaded_files++;

  // Upload a file by 'Attach' source.
  $this
    ->uploadFileByAttachSource($this->temporaryFile->uri, $this->temporaryFile->filename, $uploaded_files);
  $uploaded_files++;

  // Upload a file by 'Upload' source.
  $this
    ->uploadFileByUploadSource($this->temporaryFileEntity2
    ->getFileUri(), $this->temporaryFileEntity2
    ->getFilename(), $uploaded_files, TRUE);
  $uploaded_files++;

  // Upload a file by 'Clipboard' source.
  $this
    ->uploadFileByClipboardSource($this->temporaryFileEntity1
    ->getFileUri(), $this->temporaryFileEntity1
    ->getFileName(), $uploaded_files);
  $uploaded_files++;

  // Upload a file by 'Imce' source.
  $this
    ->uploadFileByImceSource($this->permanentFileEntity2
    ->getFileUri(), $this->permanentFileEntity2
    ->getFileName(), $uploaded_files);
  $uploaded_files++;

  // Ensure files have been uploaded.
  $remove_buttons = $this
    ->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]');
  $this
    ->assertEqual(count($remove_buttons), $uploaded_files, "There are {$uploaded_files} files have been uploaded.");
  return $uploaded_files;
}