You are here

public function EntityFileTest::testWriteFile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/Migrate/EntityFileTest.php \Drupal\file\Tests\Migrate\EntityFileTest::testWriteFile()

Tests various invocations of the writeFile() method.

File

core/modules/file/src/Tests/Migrate/EntityFileTest.php, line 104
Contains \Drupal\file\Tests\Migrate\EntityFileTest.

Class

EntityFileTest
Tests the entity file destination plugin.

Namespace

Drupal\file\Tests\Migrate

Code

public function testWriteFile() {
  $plugin = $this->destination;
  $method = new \ReflectionMethod($plugin, 'writeFile');
  $method
    ->setAccessible(TRUE);
  touch('temporary://baz.txt');

  // Moving an actual file should return TRUE.
  $plugin->configuration['move'] = TRUE;
  $this
    ->assertTrue($method
    ->invoke($plugin, 'temporary://baz.txt', 'public://foo.txt'));

  // Trying to move a non-existent file should return FALSE.
  $this
    ->assertFalse($method
    ->invoke($plugin, 'temporary://invalid.txt', 'public://invalid.txt'));

  // Copying over a file that already exists should replace the existing file.
  $plugin->configuration['move'] = FALSE;
  touch('temporary://baz.txt');
  $this
    ->assertTrue($method
    ->invoke($plugin, 'temporary://baz.txt', 'public://foo.txt'));

  // Copying over a file that already exists should rename the resulting file
  // if FILE_EXISTS_RENAME is specified.
  $method
    ->invoke($plugin, 'temporary://baz.txt', 'public://foo.txt', FILE_EXISTS_RENAME);
  $this
    ->assertTrue(file_exists('public://foo_0.txt'));

  // Trying to copy a non-existent file should return FALSE.
  $this
    ->assertFalse($method
    ->invoke($plugin, 'temporary://invalid.txt', 'public://invalid.txt'));
}