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