InterlaceTest.php in Image Effects 8
File
tests/src/Functional/Effect/InterlaceTest.php
View source
<?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Core\Image\ImageInterface;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class InterlaceTest extends ImageEffectsTestBase {
public function providerToolkits() {
$toolkits = parent::providerToolkits();
unset($toolkits['ImageMagick-graphicsmagick']);
return $toolkits;
}
public function testInterlaceEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$test_data = [
[
'test_file' => $this
->getTestImageCopyUri('/files/image-test.png', 'simpletest'),
],
];
$effect = [
'id' => 'image_effects_interlace',
'data' => [
'type' => 'Plane',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
foreach ($test_data as $data) {
$original_uri = $data['test_file'];
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertTrue($this
->isPngInterlaced($image));
}
$uuid = $this
->removeEffectFromTestStyle($uuid);
}
protected function isPngInterlaced(ImageInterface $image) {
$source = $image
->getSource();
$real_path = $this->container
->get('file_system')
->realpath($source);
$handle = fopen($real_path, "r");
$contents = fread($handle, 32);
fclose($handle);
return ord($contents[28]) != 0;
}
}