3 namespace Drupal\system\Tests\Image;
6 * Tests image toolkit functions.
10 class ToolkitTest extends ToolkitTestBase {
12 * Check that ImageToolkitManager::getAvailableToolkits() only returns
15 public function testGetAvailableToolkits() {
16 $manager = $this->container->get('image.toolkit.manager');
17 $toolkits = $manager->getAvailableToolkits();
18 $this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.');
19 $this->assertTrue(isset($toolkits['test:derived_toolkit']), 'The derived toolkit was returned.');
20 $this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned');
21 $this->assertToolkitOperationsCalled([]);
25 * Tests Image's methods.
27 public function testLoad() {
28 $image = $this->getImage();
29 $this->assertTrue(is_object($image), 'Returned an object.');
30 $this->assertEqual($image->getToolkitId(), 'test', 'Image had toolkit set.');
31 $this->assertToolkitOperationsCalled(['parseFile']);
35 * Test the image_save() function.
37 public function testSave() {
38 $this->assertFalse($this->image->save(), 'Function returned the expected value.');
39 $this->assertToolkitOperationsCalled(['save']);
43 * Test the image_apply() function.
45 public function testApply() {
46 $data = ['p1' => 1, 'p2' => TRUE, 'p3' => 'text'];
47 $this->assertTrue($this->image->apply('my_operation', $data), 'Function returned the expected value.');
49 // Check that apply was called and with the correct parameters.
50 $this->assertToolkitOperationsCalled(['apply']);
51 $calls = $this->imageTestGetAllCalls();
52 $this->assertEqual($calls['apply'][0][0], 'my_operation', "'my_operation' was passed correctly as operation");
53 $this->assertEqual($calls['apply'][0][1]['p1'], 1, 'integer parameter p1 was passed correctly');
54 $this->assertEqual($calls['apply'][0][1]['p2'], TRUE, 'boolean parameter p2 was passed correctly');
55 $this->assertEqual($calls['apply'][0][1]['p3'], 'text', 'string parameter p3 was passed correctly');
59 * Test the image_apply() function.
61 public function testApplyNoParameters() {
62 $this->assertTrue($this->image->apply('my_operation'), 'Function returned the expected value.');
64 // Check that apply was called and with the correct parameters.
65 $this->assertToolkitOperationsCalled(['apply']);
66 $calls = $this->imageTestGetAllCalls();
67 $this->assertEqual($calls['apply'][0][0], 'my_operation', "'my_operation' was passed correctly as operation");
68 $this->assertEqual($calls['apply'][0][1], [], 'passing no parameters was handled correctly');
72 * Tests image toolkit operations inheritance by derivative toolkits.
74 public function testDerivative() {
75 $toolkit_manager = $this->container->get('image.toolkit.manager');
76 $operation_manager = $this->container->get('image.toolkit.operation.manager');
78 $toolkit = $toolkit_manager->createInstance('test:derived_toolkit');
80 // Load an overwritten and an inherited operation.
81 $blur = $operation_manager->getToolkitOperation($toolkit, 'blur');
82 $invert = $operation_manager->getToolkitOperation($toolkit, 'invert');
84 $this->assertIdentical('foo_derived', $blur->getPluginId(), "'Blur' operation overwritten by derivative.");
85 $this->assertIdentical('bar', $invert->getPluginId(), '"Invert" operation inherited from base plugin.');