17c91158c2658e411c3ee7a9a0538f907d7065a7
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Image / ToolkitTest.php
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   /**
13    * Check that ImageToolkitManager::getAvailableToolkits() only returns
14    * available toolkits.
15    */
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([]);
23   }
24
25   /**
26    * Tests Image's methods.
27    */
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']);
33   }
34
35   /**
36    * Test the image_save() function.
37    */
38   public function testSave() {
39     $this->assertFalse($this->image->save(), 'Function returned the expected value.');
40     $this->assertToolkitOperationsCalled(['save']);
41   }
42
43   /**
44    * Test the image_apply() function.
45    */
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.');
49
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');
57   }
58
59   /**
60    * Test the image_apply() function.
61    */
62   public function testApplyNoParameters() {
63     $this->assertTrue($this->image->apply('my_operation'), 'Function returned the expected value.');
64
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');
70   }
71
72   /**
73    * Tests image toolkit operations inheritance by derivative toolkits.
74    */
75   public function testDerivative() {
76     $toolkit_manager = $this->container->get('image.toolkit.manager');
77     $operation_manager = $this->container->get('image.toolkit.operation.manager');
78
79     $toolkit = $toolkit_manager->createInstance('test:derived_toolkit');
80
81     // Load an overwritten and an inherited operation.
82     $blur = $operation_manager->getToolkitOperation($toolkit, 'blur');
83     $invert = $operation_manager->getToolkitOperation($toolkit, 'invert');
84
85     $this->assertIdentical('foo_derived', $blur->getPluginId(), "'Blur' operation overwritten by derivative.");
86     $this->assertIdentical('bar', $invert->getPluginId(), '"Invert" operation inherited from base plugin.');
87   }
88
89 }