You are here

public function ToolkitImagemagickTest::testTemporaryRemoteCopiesDeletion in ImageMagick 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/ToolkitImagemagickTest.php \Drupal\Tests\imagemagick\Functional\ToolkitImagemagickTest::testTemporaryRemoteCopiesDeletion()

Test removal of temporary files created during operations on remote files.

@dataProvider providerToolkitConfiguration

Parameters

string $toolkit_id: The id of the toolkit to set up.

string $toolkit_config: The config object of the toolkit to set up.

array $toolkit_settings: The settings of the toolkit to set up.

File

tests/src/Functional/ToolkitImagemagickTest.php, line 81

Class

ToolkitImagemagickTest
Tests that core image manipulations work properly through Imagemagick.

Namespace

Drupal\Tests\imagemagick\Functional

Code

public function testTemporaryRemoteCopiesDeletion($toolkit_id, $toolkit_config, array $toolkit_settings) {
  $this
    ->setUpToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
  $this
    ->prepareImageFileHandling();

  // Get metadata from a remote file.
  $image = $this->imageFactory
    ->get('dummy-remote://image-test.png');
  $image
    ->getToolkit()
    ->getExifOrientation();
  $this
    ->assertCount(1, file_scan_directory('temporary://', '/ima.*/'), 'A temporary file has been created for getting metadata from a remote file.');

  // Simulate Drupal shutdown.
  $callbacks = drupal_register_shutdown_function();
  foreach ($callbacks as $callback) {
    if ($callback['callback'] === [
      ImagemagickEventSubscriber::class,
      'removeTemporaryRemoteCopy',
    ]) {
      call_user_func_array($callback['callback'], $callback['arguments']);
    }
  }

  // Ensure we have no leftovers in the temporary directory.
  $this
    ->assertCount(0, file_scan_directory('temporary://', '/ima.*/'), 'No files left in the temporary directory after the Drupal shutdown.');
}