You are here

public function FileMoveTest::testNormal in Drupal 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testNormal()
  2. 8 core/modules/image/tests/src/Functional/FileMoveTest.php \Drupal\Tests\image\Functional\FileMoveTest::testNormal()
Same name and namespace in other branches
  1. 9 core/modules/image/tests/src/Functional/FileMoveTest.php \Drupal\Tests\image\Functional\FileMoveTest::testNormal()

Tests moving a randomly generated image.

File

core/modules/image/tests/src/Functional/FileMoveTest.php, line 38

Class

FileMoveTest
Tests the file move function for images and image styles.

Namespace

Drupal\Tests\image\Functional

Code

public function testNormal() {

  // Pick a file for testing.
  $file = File::create((array) current($this
    ->drupalGetTestFiles('image')));

  // Create derivative image.
  $styles = ImageStyle::loadMultiple();
  $style = reset($styles);
  $original_uri = $file
    ->getFileUri();
  $derivative_uri = $style
    ->buildUri($original_uri);
  $style
    ->createDerivative($original_uri, $derivative_uri);

  // Check if derivative image exists.
  $this
    ->assertFileExists($derivative_uri);

  // Clone the object so we don't have to worry about the function changing
  // our reference copy.
  $desired_filepath = 'public://' . $this
    ->randomMachineName();
  $result = file_move(clone $file, $desired_filepath, FileSystemInterface::EXISTS_ERROR);

  // Check if image has been moved.
  $this
    ->assertFileExists($result
    ->getFileUri());

  // Check if derivative image has been flushed.
  $this
    ->assertFileNotExists($derivative_uri);
}