You are here

public function FileMetadataExifTest::testTiffExifSaveToFile in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 file_mdm_exif/tests/src/Kernel/FileMetadataExifTest.php \Drupal\Tests\file_mdm_exif\Kernel\FileMetadataExifTest::testTiffExifSaveToFile()

Test writing metadata to TIFF file.

File

file_mdm_exif/tests/src/Kernel/FileMetadataExifTest.php, line 320

Class

FileMetadataExifTest
Tests that File Metadata EXIF plugin works properly.

Namespace

Drupal\Tests\file_mdm_exif\Kernel

Code

public function testTiffExifSaveToFile() {
  $fmdm = $this->container
    ->get('file_metadata_manager');

  // Copy test file to public://.
  file_unmanaged_copy(drupal_get_path('module', 'file_mdm') . '/tests/files/sample-1.tiff', 'public://', FILE_EXISTS_REPLACE);
  $file_uri = 'public://sample-1.tiff';
  $file_metadata = $fmdm
    ->uri($file_uri);

  // Check values via exif_read_data before operations.
  $data = @exif_read_data($file_uri);
  $this
    ->assertEquals(1, $data['Orientation']);
  $this
    ->assertEquals(2, $data['PhotometricInterpretation']);

  // Change tags from IFD0.
  $this
    ->assertEquals(1, $file_metadata
    ->getMetadata('exif', 'orientation')['value']);
  $this
    ->assertTrue($file_metadata
    ->setMetadata('exif', 'orientation', 4));
  $this
    ->assertEquals(4, $file_metadata
    ->getMetadata('exif', 'orientation')['value']);
  $this
    ->assertEquals(2, $file_metadata
    ->getMetadata('exif', 'PhotometricInterpretation')['value']);
  $this
    ->assertTrue($file_metadata
    ->setMetadata('exif', 'PhotometricInterpretation', 4));
  $this
    ->assertEquals(4, $file_metadata
    ->getMetadata('exif', 'PhotometricInterpretation')['value']);

  // Save metadata to file.
  $this
    ->assertTrue($file_metadata
    ->saveMetadataToFile('exif'));

  // Check results via exif_read_data.
  $data = @exif_read_data($file_uri);
  $this
    ->assertEquals(4, $data['Orientation']);
  $this
    ->assertEquals(4, $data['PhotometricInterpretation']);
}