ImageStyleQualityTest.php in Image Style Quality 8
File
tests/src/Kernel/ImageStyleQualityTest.php
View source
<?php
namespace Drupal\Tests\image_style_quality\Kernel;
use Drupal\image\Entity\ImageStyle;
use Drupal\KernelTests\KernelTestBase;
class ImageStyleQualityTest extends KernelTestBase {
public static $modules = [
'image_style_quality',
'image',
'system',
];
protected $styleName = 'test_style';
protected $testQuality = 5;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('image_style');
$this
->installConfig('system');
$style = ImageStyle::create([
'name' => $this->styleName,
]);
$style
->addImageEffect([
'id' => 'image_style_quality',
'data' => [
'quality' => $this->testQuality,
],
]);
$style
->save();
}
public function testImageQuality($toolkit) {
$this
->config('system.image')
->set('toolkit', $toolkit)
->save();
$style = ImageStyle::load($this->styleName);
$original_uri = __DIR__ . '/../../fixtures/original.jpg';
$derivative_uri = 'public://test-image.jpg';
$style
->createDerivative($original_uri, $derivative_uri);
$this
->assertTrue(filesize($original_uri) > filesize($derivative_uri) * 2);
}
public function imageQualityTestCases() {
return [
'GD' => [
'gd',
],
'Imagemagick' => [
'imagemagick',
],
];
}
}