comparison core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\FunctionalTests\Image;
4
5 /**
6 * Tests image toolkit functions.
7 *
8 * @group Image
9 */
10 class ToolkitTest extends ToolkitTestBase {
11 /**
12 * Check that ImageToolkitManager::getAvailableToolkits() only returns
13 * available toolkits.
14 */
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([]);
22 }
23
24 /**
25 * Tests Image's methods.
26 */
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']);
32 }
33
34 /**
35 * Test the image_save() function.
36 */
37 public function testSave() {
38 $this->assertFalse($this->image->save(), 'Function returned the expected value.');
39 $this->assertToolkitOperationsCalled(['save']);
40 }
41
42 /**
43 * Test the image_apply() function.
44 */
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.');
48
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');
56 }
57
58 /**
59 * Test the image_apply() function.
60 */
61 public function testApplyNoParameters() {
62 $this->assertTrue($this->image->apply('my_operation'), 'Function returned the expected value.');
63
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');
69 }
70
71 /**
72 * Tests image toolkit operations inheritance by derivative toolkits.
73 */
74 public function testDerivative() {
75 $toolkit_manager = $this->container->get('image.toolkit.manager');
76 $operation_manager = $this->container->get('image.toolkit.operation.manager');
77
78 $toolkit = $toolkit_manager->createInstance('test:derived_toolkit');
79
80 // Load an overwritten and an inherited operation.
81 $blur = $operation_manager->getToolkitOperation($toolkit, 'blur');
82 $invert = $operation_manager->getToolkitOperation($toolkit, 'invert');
83
84 $this->assertIdentical('foo_derived', $blur->getPluginId(), "'Blur' operation overwritten by derivative.");
85 $this->assertIdentical('bar', $invert->getPluginId(), '"Invert" operation inherited from base plugin.');
86 }
87
88 }