View source
<?php
namespace Drupal\FunctionalTests\Image;
class ToolkitTest extends ToolkitTestBase {
protected $defaultTheme = 'stark';
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([]);
}
public function testLoad() {
$image = $this
->getImage();
$this
->assertIsObject($image);
$this
->assertEqual($image
->getToolkitId(), 'test', 'Image had toolkit set.');
$this
->assertToolkitOperationsCalled([
'parseFile',
]);
}
public function testSave() {
$this
->assertFalse($this->image
->save(), 'Function returned the expected value.');
$this
->assertToolkitOperationsCalled([
'save',
]);
}
public function testApply() {
$data = [
'p1' => 1,
'p2' => TRUE,
'p3' => 'text',
];
$this
->assertTrue($this->image
->apply('my_operation', $data), 'Function returned the expected value.');
$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');
}
public function testApplyNoParameters() {
$this
->assertTrue($this->image
->apply('my_operation'), 'Function returned the expected value.');
$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');
}
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');
$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.');
}
}