You are here

ConvolutionSharpenTest.php in Image Effects 8.3

File

tests/src/Functional/Effect/ConvolutionSharpenTest.php
View source
<?php

namespace Drupal\Tests\image_effects\Functional\Effect;

use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;

/**
 * Convolution sharpen effect test.
 *
 * @group Image Effects
 */
class ConvolutionSharpenTest extends ImageEffectsTestBase {

  /**
   * {@inheritdoc}
   */
  public function providerToolkits() {
    $toolkits = parent::providerToolkits();

    // @todo This effect does not work on GraphicsMagick.
    unset($toolkits['ImageMagick-graphicsmagick']);
    return $toolkits;
  }

  /**
   * Convolution sharpen effect test.
   *
   * @param string $toolkit_id
   *   The id of the toolkit to set up.
   * @param string $toolkit_config
   *   The config object of the toolkit to set up.
   * @param array $toolkit_settings
   *   The settings of the toolkit to set up.
   *
   * @dataProvider providerToolkits
   */
  public function testConvolutionSharpenEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
    $this
      ->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
    $original_uri = $this
      ->getTestImageCopyUri('core/tests/fixtures/files/image-test.png');
    $derivative_uri = 'public://test-images/image-test-derived.png';

    // Add convolution sharpen effect to the test image style.
    $effect = [
      'id' => 'image_effects_convolution_sharpen',
      'data' => [
        'level' => 10,
      ],
    ];
    $uuid = $this
      ->addEffectToTestStyle($effect);

    // Apply the operation, via the effect.
    $image = $this->imageFactory
      ->get($original_uri);
    $effect = $this->testImageStyle
      ->getEffect($uuid);
    $effect
      ->applyEffect($image);

    // Toolkit-specific tests.
    switch ($this->imageFactory
      ->getToolkitId()) {
      case 'gd':

        // For the GD toolkit, just test derivative image is valid.
        $image
          ->save($derivative_uri);
        $derivative_image = $this->imageFactory
          ->get($derivative_uri);
        $this
          ->assertTrue($derivative_image
          ->isValid());
        break;
      case 'imagemagick':

        // For the Imagemagick toolkit, check the command line argument has
        // been formatted properly.
        $find = $image
          ->getToolkit()
          ->arguments()
          ->find('/^./', NULL, [
          'image_toolkit_operation' => 'convolution',
        ]);
        $arg = array_shift($find);
        $this
          ->assertEquals("-morphology Convolve '3x3:-0.1,-0.1,-0.1 -0.1,1.8,-0.1 -0.1,-0.1,-0.1'", $arg['argument']);
        break;
    }

    // Remove effect.
    $this
      ->removeEffectFromTestStyle($uuid);
  }

}

Classes

Namesort descending Description
ConvolutionSharpenTest Convolution sharpen effect test.