You are here

public function ToolkitImagemagickFileMetadataTest::testSourceLocalPath in ImageMagick 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ToolkitImagemagickFileMetadataTest.php \Drupal\Tests\imagemagick\Functional\ToolkitImagemagickFileMetadataTest::testSourceLocalPath()

Tests getSourceLocalPath() for re-creating local path.

@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/ToolkitImagemagickFileMetadataTest.php, line 481

Class

ToolkitImagemagickFileMetadataTest
Tests that Imagemagick integrates properly with File Metadata Manager.

Namespace

Drupal\Tests\imagemagick\Functional

Code

public function testSourceLocalPath(string $toolkit_id, string $toolkit_config, array $toolkit_settings) : void {
  $this
    ->setUpToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
  $this
    ->prepareImageFileHandling();
  $config_mdm = \Drupal::configFactory()
    ->getEditable('file_mdm.settings');

  // The file metadata manager service.
  $fmdm = $this->container
    ->get('file_metadata_manager');

  // The file that will be tested.
  $source_uri = 'public://image-test.png';

  // Enable metadata caching.
  $config_mdm
    ->set('metadata_cache.enabled', TRUE)
    ->save();

  // Load up the image.
  $image = $this->imageFactory
    ->get($source_uri);
  $this
    ->assertEquals($source_uri, $image
    ->getToolkit()
    ->getSource());
  $this
    ->assertEquals($this->fileSystem
    ->realpath($source_uri), $image
    ->getToolkit()
    ->arguments()
    ->getSourceLocalPath());

  // Free up the URI from the file metadata manager to force reload from
  // cache. Simulates that next imageFactory->get is from another request.
  $fmdm
    ->release($source_uri);

  // Re-load the image, ensureLocalSourcePath should return the local path.
  $image1 = $this->imageFactory
    ->get($source_uri);
  $this
    ->assertEquals($source_uri, $image1
    ->getToolkit()
    ->getSource());
  $this
    ->assertEquals($this->fileSystem
    ->realpath($source_uri), $image1
    ->getToolkit()
    ->ensureSourceLocalPath());
}