You are here

public function AttachSourceTest::testMoveFilesFromRelativePath in FileField Sources 8

Tests move relative files with different names.

Default settings: Move file from 'public://file_attach' to 'public://'.

File

tests/src/Functional/AttachSourceTest.php, line 19

Class

AttachSourceTest
Tests the attach source.

Namespace

Drupal\Tests\filefield_sources\Functional

Code

public function testMoveFilesFromRelativePath() {
  $uri_scheme = $this
    ->getFieldSetting('uri_scheme');
  $path = $uri_scheme . '://' . FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH . '/';
  $this
    ->enableSources([
    'attach' => TRUE,
  ]);

  // File with a random name.
  $file = $this
    ->createTemporaryFile($path);
  $dest_uri = $this
    ->getDestinationUri($file, $uri_scheme);
  $this
    ->drupalGet('node/add/' . $this->typeName);
  $this
    ->fileCanBeUploadAndDeleted($file, $dest_uri);

  // File with an space in the name.
  $file = $this
    ->createTemporaryFile($path, 'test file.txt');
  $dest_uri = $this
    ->getDestinationUri($file, $uri_scheme);
  $this
    ->drupalGet('node/add/' . $this->typeName);
  $this
    ->fileCanBeUploadAndDeleted($file, $dest_uri);

  // File with special characters in the name that are going to be
  // transliterated.
  $original_filename = 'file_áéíóú_ññ.txt';
  $transliterated_filename = 'file_aeiou_nn.txt';
  $file = $this
    ->createTemporaryFile($path, $original_filename);
  $file->filename = $transliterated_filename;
  $dest_uri = $this
    ->getDestinationUri($file, $uri_scheme);
  $this
    ->drupalGet('node/add/' . $this->typeName);
  $this
    ->fileCanBeUploadAndDeleted($file, $dest_uri);
}