Mercurial > hg > cmmr2012-drupal-site
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php Thu Jul 05 14:24:15 2018 +0000 @@ -0,0 +1,88 @@ +<?php + +namespace Drupal\FunctionalTests\Image; + +/** + * Tests image toolkit functions. + * + * @group Image + */ +class ToolkitTest extends ToolkitTestBase { + /** + * Check that ImageToolkitManager::getAvailableToolkits() only returns + * available toolkits. + */ + public function testGetAvailableToolkits() { + $manager = $this->container->get('image.toolkit.manager'); + $toolkits = $manager->getAvailableToolkits(); + $this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.'); + $this->assertTrue(isset($toolkits['test:derived_toolkit']), 'The derived toolkit was returned.'); + $this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned'); + $this->assertToolkitOperationsCalled([]); + } + + /** + * Tests Image's methods. + */ + public function testLoad() { + $image = $this->getImage(); + $this->assertTrue(is_object($image), 'Returned an object.'); + $this->assertEqual($image->getToolkitId(), 'test', 'Image had toolkit set.'); + $this->assertToolkitOperationsCalled(['parseFile']); + } + + /** + * Test the image_save() function. + */ + public function testSave() { + $this->assertFalse($this->image->save(), 'Function returned the expected value.'); + $this->assertToolkitOperationsCalled(['save']); + } + + /** + * Test the image_apply() function. + */ + public function testApply() { + $data = ['p1' => 1, 'p2' => TRUE, 'p3' => 'text']; + $this->assertTrue($this->image->apply('my_operation', $data), 'Function returned the expected value.'); + + // Check that apply was called and with the correct parameters. + $this->assertToolkitOperationsCalled(['apply']); + $calls = $this->imageTestGetAllCalls(); + $this->assertEqual($calls['apply'][0][0], 'my_operation', "'my_operation' was passed correctly as operation"); + $this->assertEqual($calls['apply'][0][1]['p1'], 1, 'integer parameter p1 was passed correctly'); + $this->assertEqual($calls['apply'][0][1]['p2'], TRUE, 'boolean parameter p2 was passed correctly'); + $this->assertEqual($calls['apply'][0][1]['p3'], 'text', 'string parameter p3 was passed correctly'); + } + + /** + * Test the image_apply() function. + */ + public function testApplyNoParameters() { + $this->assertTrue($this->image->apply('my_operation'), 'Function returned the expected value.'); + + // Check that apply was called and with the correct parameters. + $this->assertToolkitOperationsCalled(['apply']); + $calls = $this->imageTestGetAllCalls(); + $this->assertEqual($calls['apply'][0][0], 'my_operation', "'my_operation' was passed correctly as operation"); + $this->assertEqual($calls['apply'][0][1], [], 'passing no parameters was handled correctly'); + } + + /** + * Tests image toolkit operations inheritance by derivative toolkits. + */ + public function testDerivative() { + $toolkit_manager = $this->container->get('image.toolkit.manager'); + $operation_manager = $this->container->get('image.toolkit.operation.manager'); + + $toolkit = $toolkit_manager->createInstance('test:derived_toolkit'); + + // Load an overwritten and an inherited operation. + $blur = $operation_manager->getToolkitOperation($toolkit, 'blur'); + $invert = $operation_manager->getToolkitOperation($toolkit, 'invert'); + + $this->assertIdentical('foo_derived', $blur->getPluginId(), "'Blur' operation overwritten by derivative."); + $this->assertIdentical('bar', $invert->getPluginId(), '"Invert" operation inherited from base plugin.'); + } + +}