public function TextimageApiTest::testTargetExtension in Textimage 8.3
Same name and namespace in other branches
- 8.4 tests/src/Kernel/TextimageApiTest.php \Drupal\Tests\textimage\Kernel\TextimageApiTest::testTargetExtension()
Test output image file extension is consistent with source image.
File
- tests/
src/ Kernel/ TextimageApiTest.php, line 204
Class
- TextimageApiTest
- Kernel tests for Textimage API.
Namespace
Drupal\Tests\textimage\KernelCode
public function testTargetExtension() {
$files = $this
->getTestFiles('image');
// Get 'image-test.gif'.
$file = File::create((array) $files[1]);
$file
->save();
$textimage = $this->textimageFactory
->get();
$textimage
->setStyle(ImageStyle::load('textimage_test'))
->setSourceImageFile($file)
->process([
'bingox',
])
->buildImage();
$image = \Drupal::service('image.factory')
->get($textimage
->getUri());
$this
->assertSame('image/gif', $image
->getMimeType());
// Test loading the Textimage metadata.
$id = $textimage
->id();
$uri = $textimage
->getUri();
$textimage = $this->textimageFactory
->load($id);
$style = ImageStyle::load('textimage_test');
// Check loaded data.
$this
->assertSame($id, $textimage
->id());
$this
->assertSame($uri, $textimage
->getUri());
$this
->assertSame([
'bingox',
], $textimage
->getText());
$this
->setExpectedException(TextimageException::class, 'Textimage error: Attempted to set property \'style\' when image was processed already');
$textimage
->setStyle($style);
// File exists.
$this
->assertFileExists($uri);
// File deletion.
$this
->assertTrue($this->fileSystem
->delete($uri));
// Reload and rebuild.
$textimage = $this->textimageFactory
->load($id);
$textimage
->buildImage();
$this
->assertFileExists($uri);
}