You are here

public function AutoOrientTest::testAutoOrientAllTags in Image Effects 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/Effect/AutoOrientTest.php \Drupal\Tests\image_effects\Functional\Effect\AutoOrientTest::testAutoOrientAllTags()
  2. 8.2 tests/src/Functional/Effect/AutoOrientTest.php \Drupal\Tests\image_effects\Functional\Effect\AutoOrientTest::testAutoOrientAllTags()

Auto Orientation effect test, all EXIF orientation tags.

@dataProvider providerToolkits

Parameters

string $toolkit_id: The id of the toolkit to set up.

string $toolkit_config: The config object of the toolkit to set up.

array $toolkit_settings: The settings of the toolkit to set up.

File

tests/src/Functional/Effect/AutoOrientTest.php, line 126

Class

AutoOrientTest
Auto Orientation effect test.

Namespace

Drupal\Tests\image_effects\Functional\Effect

Code

public function testAutoOrientAllTags($toolkit_id, $toolkit_config, array $toolkit_settings) {
  $this
    ->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);

  // Add Auto Orient effect to the test image style.
  $effect = [
    'id' => 'image_effects_auto_orient',
    'data' => [
      'scan_exif' => TRUE,
    ],
  ];
  $this
    ->addEffectToTestStyle($effect);
  $test_data = [];
  for ($i = 1; $i < 9; $i++) {
    $test_data[$i]['test_file'] = drupal_get_path('module', 'image_effects') . "/tests/images/image-test-exif-orientation-{$i}.jpeg";
  }
  foreach ($test_data as $data) {

    // Get URI of test file.
    $original_uri = $data['test_file'];

    // Check that ::applyEffect generates image with expected dimensions and
    // colors at corners.
    $derivative_uri = $this->testImageStyle
      ->buildUri($original_uri);
    $this->testImageStyle
      ->createDerivative($original_uri, $derivative_uri);
    $image = $this->imageFactory
      ->get($derivative_uri, 'gd');
    $this
      ->assertEqual(120, $image
      ->getWidth());
    $this
      ->assertEqual(60, $image
      ->getHeight());
    $this
      ->assertColorsAreClose($this->red, $this
      ->getPixelColor($image, 0, 0), 10);
    $this
      ->assertColorsAreClose($this->green, $this
      ->getPixelColor($image, 119, 0), 10);
    $this
      ->assertColorsAreClose($this->yellow, $this
      ->getPixelColor($image, 0, 59), 10);
    $this
      ->assertColorsAreClose($this->blue, $this
      ->getPixelColor($image, 119, 59), 10);
  }
}