public function ConvolutionTest::testConvolutionEffect in Image Effects 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/Effect/ConvolutionTest.php \Drupal\Tests\image_effects\Functional\Effect\ConvolutionTest::testConvolutionEffect()
- 8.2 tests/src/Functional/Effect/ConvolutionTest.php \Drupal\Tests\image_effects\Functional\Effect\ConvolutionTest::testConvolutionEffect()
Convolution effect test.
@dataProvider providerToolkits
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/ Effect/ ConvolutionTest.php, line 36
Class
- ConvolutionTest
- Convolution effect test.
Namespace
Drupal\Tests\image_effects\Functional\EffectCode
public function testConvolutionEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$original_uri = $this
->getTestImageCopyUri('/files/image-test.png', 'simpletest');
$derivative_uri = 'public://test-images/image-test-derived.png';
// Add the effect for operation test.
$effect = [
'id' => 'image_effects_convolution',
'data' => [
'kernel][entries][0][0' => 9,
'kernel][entries][0][1' => 9,
'kernel][entries][0][2' => 9,
'kernel][entries][1][0' => 9,
'kernel][entries][1][1' => 9,
'kernel][entries][1][2' => 9,
'kernel][entries][2][0' => 9,
'kernel][entries][2][1' => 9,
'kernel][entries][2][2' => 9,
'divisor' => 9,
'offset' => 0,
'label' => 'test_convolution',
],
];
$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.
$argument = $image
->getToolkit()
->getArguments()[$image
->getToolkit()
->findArgument('-morphology')];
$this
->assertEqual("-morphology Convolve '3x3:1,1,1 1,1,1 1,1,1'", $argument);
break;
}
// Remove effect.
$this
->removeEffectFromTestStyle($uuid);
}