public function TextOverlayTest::testTextOverlayEffect in Image Effects 8.3
Same name and namespace in other branches
- 8 tests/src/Functional/Effect/TextOverlayTest.php \Drupal\Tests\image_effects\Functional\Effect\TextOverlayTest::testTextOverlayEffect()
- 8.2 tests/src/Functional/Effect/TextOverlayTest.php \Drupal\Tests\image_effects\Functional\Effect\TextOverlayTest::testTextOverlayEffect()
Text overlay effect test.
@dataProvider providerToolkits
Parameters
string $toolkit_id: The id of the toolkit to set up.
string $toolkit_config: The config object of the toolkit to set up.
array $toolkit_settings: The settings of the toolkit to set up.
File
- tests/
src/ Functional/ Effect/ TextOverlayTest.php, line 49
Class
- TextOverlayTest
- Text overlay effect test.
Namespace
Drupal\Tests\image_effects\Functional\EffectCode
public function testTextOverlayEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
// Copy the font file to the test path.
$this->fileSystem
->copy(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf', 'dummy-remote://', FileSystemInterface::EXISTS_REPLACE);
// Add Text overlay effects to the test image style.
// Different ways to access the same font file, via URI (local and remote),
// and local path.
$effect_config = [
'id' => 'image_effects_text_overlay',
'data' => [
'text_default][text_string' => 'the quick brown fox jumps over the lazy dog',
'font][uri' => drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf',
'font][size' => 40,
'layout][position][extended_color][container][transparent' => FALSE,
'layout][position][extended_color][container][hex' => '#FF00FF',
'layout][position][extended_color][container][opacity' => 100,
],
];
$this
->addEffectToTestStyle($effect_config);
$effect_config = [
'id' => 'image_effects_text_overlay',
'data' => [
'text_default][text_string' => 'the quick brown fox jumps over the lazy dog',
'font][uri' => 'public://LinLibertine_Rah.ttf',
'font][size' => 10,
'layout][position][extended_color][container][transparent' => FALSE,
'layout][position][extended_color][container][hex' => '#FF00FF',
'layout][position][extended_color][container][opacity' => 100,
],
];
$this
->addEffectToTestStyle($effect_config);
$effect_config = [
'id' => 'image_effects_text_overlay',
'data' => [
'text_default][text_string' => 'the quick brown fox jumps over the lazy dog',
'font][uri' => 'dummy-remote://LinLibertine_Rah.ttf',
'font][size' => 10,
'layout][position][extended_color][container][transparent' => FALSE,
'layout][position][extended_color][container][hex' => '#FF00FF',
'layout][position][extended_color][container][opacity' => 100,
],
];
$this
->addEffectToTestStyle($effect_config);
// Check that no temporary files are left in Imagemagick.
if ($toolkit_id === 'imagemagick') {
$directory_scan = $this->fileSystem
->scanDirectory('temporary://', '/ifx.*/');
$this
->assertEquals(0, count($directory_scan));
}
$test_data = [
[
'test_file' => $this
->getTestImageCopyUri('core/tests/fixtures/files/image-test.png'),
'derivative_width' => 984,
'derivative_height' => 61,
],
];
foreach ($test_data as $data) {
// Get expected URIs.
$original_uri = $data['test_file'];
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
// Source image.
$image = $this->imageFactory
->get($original_uri);
// Load Image Style and get expected derivative URL.
$derivative_url = file_url_transform_relative($this->testImageStyle
->buildUrl($original_uri));
// Check that ::applyEffect generates image with expected dimensions
// and colors at corners.
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$derivative_image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertTextOverlay($derivative_image, $data['derivative_width'], $data['derivative_height']);
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($derivative_image, 0, 0));
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($derivative_image, $derivative_image
->getWidth() - 1, 0));
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($derivative_image, 0, $derivative_image
->getHeight() - 1));
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($derivative_image, $derivative_image
->getWidth() - 1, $derivative_image
->getHeight() - 1));
// Check that ::transformDimensions returns expected dimensions.
$variables = [
'#theme' => 'image_style',
'#style_name' => 'image_effects_test',
'#uri' => $original_uri,
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
];
$this
->assertRegExp("/\\<img src=\"" . preg_quote($derivative_url, '/') . "\" width=\"{$derivative_image->getWidth()}\" height=\"{$derivative_image->getHeight()}\" alt=\"\" .*class=\"image\\-style\\-image\\-effects\\-test\" \\/\\>/", $this
->getImageTag($variables));
}
}