View source
<?php
namespace Drupal\Tests\imagemagick\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\imagemagick\ImagemagickExecArguments;
class ExecArgumentsTest extends KernelTestBase {
protected static $modules = [
'imagemagick',
'file_mdm',
'sophron',
];
public function testArguments() : void {
$arguments = new ImagemagickExecArguments(\Drupal::service('imagemagick.exec_manager'));
$arguments
->add("-resize 100x75!")
->add("INTERNAL", ImagemagickExecArguments::INTERNAL)
->add("-quality 75")
->add("-hoxi 76", ImagemagickExecArguments::POST_SOURCE, 0)
->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',
]);
$this
->assertSame([
2,
], array_keys($arguments
->find('/^INTERNAL/')));
$this
->assertSame([
5,
], array_keys($arguments
->find('/^GATEAU/')));
$this
->assertSame([
6,
], array_keys($arguments
->find('/^\\-auchocolat/')));
$this
->assertSame([
7,
8,
], array_keys($arguments
->find('/^\\-addz/')));
$this
->assertSame([
7,
8,
], array_keys($arguments
->find('/.*/', NULL, [
'foo' => 'bar',
])));
$this
->assertSame([], $arguments
->find('/.*/', NULL, [
'arw' => 'moo',
]));
$this
->assertSame('-density 25 -auchocolat 90', $arguments
->toString(ImagemagickExecArguments::PRE_SOURCE));
$this
->assertSame("-hoxi 76 -resize 100x75! -quality 75 -addz 150 -addz 200", $arguments
->toString(ImagemagickExecArguments::POST_SOURCE));
$arguments
->add("-ix aa", ImagemagickExecArguments::POST_SOURCE, 4)
->add("-ix bb", ImagemagickExecArguments::POST_SOURCE, 4);
$this
->assertSame([
4,
5,
], array_keys($arguments
->find('/^\\-ix/')));
$this
->assertSame("-hoxi 76 -resize 100x75! -quality 75 -ix bb -ix aa -addz 150 -addz 200", $arguments
->toString(ImagemagickExecArguments::POST_SOURCE));
}
}