You are here

protected function ToolkitSetupTrait::setUpToolkit in ImageMagick 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ToolkitSetupTrait.php \Drupal\Tests\imagemagick\Kernel\ToolkitSetupTrait::setUpToolkit()

Sets up the image toolkit.

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.

12 calls to ToolkitSetupTrait::setUpToolkit()
EventSubscriberTest::testEventSubscriber in tests/src/Functional/EventSubscriberTest.php
Test module's event subscriber.
EventSubscriberTest::testGifCoalesce in tests/src/Functional/EventSubscriberTest.php
Test coalescence of Animated GIFs.
ToolkitImagemagickFileMetadataTest::testFileMetadata in tests/src/Functional/ToolkitImagemagickFileMetadataTest.php
Test image toolkit integration with file metadata manager.
ToolkitImagemagickFileMetadataTest::testSourceLocalPath in tests/src/Functional/ToolkitImagemagickFileMetadataTest.php
Tests getSourceLocalPath() for re-creating local path.
ToolkitImagemagickTest::testDoubleCropping in tests/src/Functional/ToolkitImagemagickTest.php
Tests that double cropping returns an image of expected dimensions.

... See full list

File

tests/src/Kernel/ToolkitSetupTrait.php, line 47

Class

ToolkitSetupTrait
Trait to manage toolkit setup tasks common across tests.

Namespace

Drupal\Tests\imagemagick\Kernel

Code

protected function setUpToolkit(string $toolkit_id, string $toolkit_config, array $toolkit_settings) : void {

  // Change the toolkit.
  \Drupal::configFactory()
    ->getEditable('system.image')
    ->set('toolkit', $toolkit_id)
    ->save();

  // Configure the toolkit.
  $config = \Drupal::configFactory()
    ->getEditable($toolkit_config);
  foreach ($toolkit_settings as $setting => $value) {
    $config
      ->set($setting, $value);
  }
  $config
    ->save();

  // Check that ImageMagick or GraphicsMagick binaries are installed, and
  // mark the test skipped if not.
  if ($toolkit_id === 'imagemagick') {
    $status = \Drupal::service('image.toolkit.manager')
      ->createInstance('imagemagick')
      ->getExecManager()
      ->checkPath('');
    if (!empty($status['errors'])) {
      $this
        ->markTestSkipped("Tests for '{$toolkit_settings['binaries']}' cannot run because the binaries are not available on the shell path.");
    }
  }

  // Set the toolkit on the image factory.
  $this->imageFactory = \Drupal::service('image.factory');
  $this->imageFactory
    ->setToolkitId($toolkit_id);
}