You are here

public function ToolkitImagemagickTest::testArgumentsLegacy in ImageMagick 8.2

Test legacy arguments handling.

@group legacy

File

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

Class

ToolkitImagemagickTest
Tests that core image manipulations work properly through Imagemagick.

Namespace

Drupal\Tests\imagemagick\Functional

Code

public function testArgumentsLegacy() {
  $this
    ->setUpToolkit('imagemagick', 'imagemagick.settings', [
    'binaries' => 'imagemagick',
    'quality' => 100,
    'debug' => TRUE,
  ]);

  // Prepare a copy of test files.
  $this
    ->getTestFiles('image');
  $image_uri = "public://image-test.png";
  $image = $this->imageFactory
    ->get($image_uri);
  if (!$image
    ->isValid()) {
    $this
      ->fail("Could not load image {$image_uri}.");
  }

  // Setup a list of arguments.
  $image
    ->getToolkit()
    ->addArgument("-resize 100x75!");

  // Internal argument.
  $image
    ->getToolkit()
    ->addArgument(">!>INTERNAL");
  $image
    ->getToolkit()
    ->addArgument("-quality 75");
  $image
    ->getToolkit()
    ->prependArgument("-hoxi 76");

  // Use methods introduced in 8.x-2.3.
  $image
    ->getToolkit()
    ->arguments()
    ->add("-density 25", ImagemagickExecArguments::PRE_SOURCE)
    ->add("GATEAU", ImagemagickExecArguments::INTERNAL)
    ->add("-auchocolat 90", ImagemagickExecArguments::PRE_SOURCE)
    ->add("-addz 150", ImagemagickExecArguments::POST_SOURCE, ImagemagickExecArguments::APPEND, [
    'foo' => 'bar',
    'qux' => 'der',
  ])
    ->add("-addz 200", ImagemagickExecArguments::POST_SOURCE, ImagemagickExecArguments::APPEND, [
    'wey' => 'lod',
    'foo' => 'bar',
  ]);

  // Test find arguments skipping identifiers.
  $this
    ->assertSame([
    0 => '-hoxi 76',
    1 => '-resize 100x75!',
    2 => '>!>INTERNAL',
    3 => '-quality 75',
    5 => '>!>GATEAU',
    7 => '-addz 150',
    8 => '-addz 200',
  ], $image
    ->getToolkit()
    ->getArguments());
  $this
    ->assertSame([
    2,
  ], array_keys($image
    ->getToolkit()
    ->arguments()
    ->find('/^INTERNAL/')));
  $this
    ->assertSame([
    5,
  ], array_keys($image
    ->getToolkit()
    ->arguments()
    ->find('/^GATEAU/')));
  $this
    ->assertSame([
    6,
  ], array_keys($image
    ->getToolkit()
    ->arguments()
    ->find('/^\\-auchocolat/')));
  $this
    ->assertSame([
    7,
    8,
  ], array_keys($image
    ->getToolkit()
    ->arguments()
    ->find('/^\\-addz/')));
  $this
    ->assertSame([
    7,
    8,
  ], array_keys($image
    ->getToolkit()
    ->arguments()
    ->find('/.*/', NULL, [
    'foo' => 'bar',
  ])));
  $this
    ->assertSame([], $image
    ->getToolkit()
    ->arguments()
    ->find('/.*/', NULL, [
    'arw' => 'moo',
  ]));
  $this
    ->assertSame(2, $image
    ->getToolkit()
    ->findArgument('>!>INTERNAL'));
  $this
    ->assertSame(5, $image
    ->getToolkit()
    ->findArgument('>!>GATEAU'));
  $this
    ->assertFalse($image
    ->getToolkit()
    ->findArgument('-auchocolat'));

  // Check resulting command line strings.
  $this
    ->assertSame('-density 25 -auchocolat 90', $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::PRE_SOURCE));
  $this
    ->assertSame("-hoxi 76 -resize 100x75! -quality 75 -addz 150 -addz 200", $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::POST_SOURCE));
  $this
    ->assertSame("-hoxi 76 -resize 100x75! -quality 75 -addz 150 -addz 200", $image
    ->getToolkit()
    ->getStringForBinary());
}