You are here

public function ImageOptimizePipelineTest::testCompoundFailureImagePipeline in Image Optimize (or ImageAPI Optimize) 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::testCompoundFailureImagePipeline()
  2. 4.x tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::testCompoundFailureImagePipeline()

Test using image pipeline that should not change the image.

File

tests/src/Kernel/ImageOptimizePipelineTest.php, line 77

Class

ImageOptimizePipelineTest
Tests Image Optimize pipelines.

Namespace

Drupal\Tests\imageapi_optimize\Kernel

Code

public function testCompoundFailureImagePipeline() {

  // 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',
  ]);

  // Add ten 1 characters.
  $pipeline
    ->addProcessor([
    'id' => 'imageapi_optimize_module_test_appendcharacters',
  ]);

  // Change the image to a green PNG, but fail the processor.
  $pipeline
    ->addProcessor([
    'id' => 'imageapi_optimize_module_test_failedgreenpng',
  ]);

  // Add ten 1 characters.
  $pipeline
    ->addProcessor([
    'id' => 'imageapi_optimize_module_test_appendcharacters',
  ]);

  // Apply the pipeline.
  $pipeline
    ->applyToImage($image_uri);

  // Check that the file was correctly 'optimized': adding 20 '1' characters.
  $this
    ->assertFileEqualsString($original_image_data . str_repeat('1', 20), $image_uri);
}