ImagemagickDeprecationTest.php in ImageMagick 8.2
File
tests/src/Functional/ImagemagickDeprecationTest.php
View source
<?php
namespace Drupal\Tests\imagemagick\Functional;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\Tests\BrowserTestBase;
class ImagemagickDeprecationTest extends BrowserTestBase {
use ExpectDeprecationTrait;
use TestFileCreationTrait;
protected $fileSystem;
protected $imageFactory;
protected $testDirectory;
protected static $modules = [
'system',
'simpletest',
'file_test',
'imagemagick',
'imagemagick_test',
'file_mdm',
];
public function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$this->imageFactory = $this->container
->get('image.factory');
$this->fileSystem = $this->container
->get('file_system');
$this->testDirectory = 'public://imagetest';
}
protected function setUpToolkit($binaries, $check_path = TRUE) {
\Drupal::configFactory()
->getEditable('system.image')
->set('toolkit', 'imagemagick')
->save();
\Drupal::configFactory()
->getEditable('imagemagick.settings')
->set('debug', TRUE)
->set('binaries', $binaries)
->set('quality', 100)
->save();
if ($check_path) {
$status = \Drupal::service('image.toolkit.manager')
->createInstance('imagemagick')
->getExecManager()
->checkPath('');
if (!empty($status['errors'])) {
$this
->markTestSkipped("Tests for '{$binaries}' cannot run because the binaries are not available on the shell path.");
}
}
$this->imageFactory
->setToolkitId('imagemagick');
$this
->assertEquals('imagemagick', $this->imageFactory
->getToolkitId(), 'The image factory is set to use the \'imagemagick\' image toolkit.');
file_unmanaged_delete_recursive($this->testDirectory);
file_prepare_directory($this->testDirectory, FILE_CREATE_DIRECTORY);
}
public function testAlterHooksDeprecation() {
$this
->setUpToolkit('imagemagick');
$this
->expectDeprecation('The deprecated alter hook hook_imagemagick_pre_parse_file_alter() is implemented in these functions: imagemagick_test_imagemagick_pre_parse_file_alter. Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::ENSURE_SOURCE_LOCAL_PATH event. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->expectDeprecation('The deprecated alter hook hook_imagemagick_arguments_alter() is implemented in these functions: imagemagick_test_imagemagick_arguments_alter. Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::PRE_IDENTIFY_EXECUTE or a ImagemagickExecutionEvent::PRE_CONVERT_EXECUTE event. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->expectDeprecation('The deprecated alter hook hook_imagemagick_post_save_alter() is implemented in these functions: imagemagick_test_imagemagick_post_save_alter. Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::POST_SAVE event. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->getTestFiles('image');
$image_uri = "public://image-test.png";
$image = $this->imageFactory
->get($image_uri);
$image
->getToolkit()
->arguments()
->add("-resize 100x75!")
->add("-quality 75");
$image
->save($image_uri . '.derived');
}
public function testGetModuleHandlerDeprecation() {
$this
->setUpToolkit('imagemagick');
$this
->expectDeprecation('The deprecated alter hook hook_imagemagick_pre_parse_file_alter() is implemented in these functions: imagemagick_test_imagemagick_pre_parse_file_alter. Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::ENSURE_SOURCE_LOCAL_PATH event. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->expectDeprecation('The deprecated alter hook hook_imagemagick_arguments_alter() is implemented in these functions: imagemagick_test_imagemagick_arguments_alter. Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::PRE_IDENTIFY_EXECUTE or a ImagemagickExecutionEvent::PRE_CONVERT_EXECUTE event. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->expectDeprecation('Drupal\\imagemagick\\ImagemagickExecManager::getModuleHandler is deprecated in 8.x-2.5, will be removed in 8.x-3.0. No replacement suggested, Imagemagick hooks have been dropped in favour of event subscribers. See https://www.drupal.org/project/imagemagick/issues/3043136.');
$this
->getTestFiles('image');
$image = $this->imageFactory
->get("public://image-test.png");
$this
->assertInstanceOf(ModuleHandlerInterface::class, $image
->getToolkit()
->getExecManager()
->getModuleHandler());
}
}