You are here

protected function ImagemagickDeprecationTest::setUpToolkit in ImageMagick 8.2

Helper to setup the image toolkit.

Parameters

string $binaries: The graphics package binaries to use for testing.

bool $check_path: Whether the path to binaries should be tested.

2 calls to ImagemagickDeprecationTest::setUpToolkit()
ImagemagickDeprecationTest::testAlterHooksDeprecation in tests/src/Functional/ImagemagickDeprecationTest.php
Test deprecation of module arguments alter hook.
ImagemagickDeprecationTest::testGetModuleHandlerDeprecation in tests/src/Functional/ImagemagickDeprecationTest.php
Test deprecation of ImagemagickExecManager::getModuleHandler.

File

tests/src/Functional/ImagemagickDeprecationTest.php, line 85

Class

ImagemagickDeprecationTest
Tests that core image manipulations work properly through Imagemagick.

Namespace

Drupal\Tests\imagemagick\Functional

Code

protected function setUpToolkit($binaries, $check_path = TRUE) {

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

  // Execute tests with selected binaries.
  \Drupal::configFactory()
    ->getEditable('imagemagick.settings')
    ->set('debug', TRUE)
    ->set('binaries', $binaries)
    ->set('quality', 100)
    ->save();
  if ($check_path) {

    // The test can only be executed if binaries are available on the shell
    // path.
    $status = \Drupal::service('image.toolkit.manager')
      ->createInstance('imagemagick')
      ->getExecManager()
      ->checkPath('');
    if (!empty($status['errors'])) {

      // Bots running automated test on d.o. do not have binaries installed,
      // so the test will be skipped; it can be run locally where binaries
      // are installed.
      $this
        ->markTestSkipped("Tests for '{$binaries}' cannot run because the binaries are not available on the shell path.");
    }
  }

  // Set the toolkit on the image factory.
  $this->imageFactory
    ->setToolkitId('imagemagick');

  // Test that the image factory is set to use the Imagemagick toolkit.
  $this
    ->assertEquals('imagemagick', $this->imageFactory
    ->getToolkitId(), 'The image factory is set to use the \'imagemagick\' image toolkit.');

  // Prepare directory.
  file_unmanaged_delete_recursive($this->testDirectory);
  file_prepare_directory($this->testDirectory, FILE_CREATE_DIRECTORY);
}