You are here

public function ImageOptimizePipelineTest::testValidImagePipeline in Image Optimize (or ImageAPI Optimize) 8.3

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

Test using image pipeline

File

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

Class

ImageOptimizePipelineTest
Tests Image Optimize pipelines.

Namespace

Drupal\Tests\imageapi_optimize\Kernel

Code

public function testValidImagePipeline() {

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

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

  // Check that the file was correctly 'optimized' to a black 1x1 PNG.
  $this
    ->assertStringEqualsFile($image_uri, base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='));
}