public function ImageOptimizePipelineTest::testFailureImagePipeline in Image Optimize (or ImageAPI Optimize) 8.2
Same name and namespace in other branches
- 8.3 tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::testFailureImagePipeline()
- 4.x tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::testFailureImagePipeline()
Test using image pipeline that should not change the image.
File
- tests/
src/ Kernel/ ImageOptimizePipelineTest.php, line 50
Class
- ImageOptimizePipelineTest
- Tests Image Optimize pipelines.
Namespace
Drupal\Tests\imageapi_optimize\KernelCode
public function testFailureImagePipeline() {
// Valid pink 1x1 PNG file.
$original_image_data = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==');
// Include special characters in the filename.
$image_uri = $this
->createUri('Файл для тестирования ' . $this
->randomMachineName() . '.png', $original_image_data);
// Check that our file has got to the filesystem correctly.
$this
->assertStringEqualsFile($image_uri, $original_image_data, 'Image data written to file successfully.');
// Setup our pipeline.
$pipeline = ImageAPIOptimizePipeline::create([
'name' => 'test',
]);
$pipeline
->addProcessor([
'id' => 'imageapi_optimize_module_test_failedgreenpng',
]);
// Apply the pipeline.
$pipeline
->applyToImage($image_uri);
// Check that the file was correctly 'optimized' to a black 1x1 PNG.
$this
->assertStringEqualsFile($image_uri, $original_image_data, 'Original image preserved.');
}