You are here

public function FileMetadataManagerTest::testSanitizedUri in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/FileMetadataManagerTest.php \Drupal\Tests\file_mdm\Kernel\FileMetadataManagerTest::testSanitizedUri()

Tests URI sanitization.

File

tests/src/Kernel/FileMetadataManagerTest.php, line 402

Class

FileMetadataManagerTest
Tests that File Metadata Manager works properly.

Namespace

Drupal\Tests\file_mdm\Kernel

Code

public function testSanitizedUri() {

  // Get the file metadata manager service.
  $fmdm = $this->container
    ->get('file_metadata_manager');

  // Copy a test file to test directory.
  $test_directory = 'public://test-images/';
  file_prepare_directory($test_directory, FILE_CREATE_DIRECTORY);
  file_unmanaged_copy(drupal_get_path('module', 'file_mdm') . '/tests/files/test-exif.jpeg', $test_directory, FILE_EXISTS_REPLACE);

  // Get file metadata object.
  $file_metadata = $fmdm
    ->uri('public://test-images/test-exif.jpeg');
  $this
    ->assertEquals(7, $this
    ->countMetadataKeys($file_metadata, 'getimagesize'));

  // Check that the file metadata manager has the URI in different forms.
  $this
    ->assertTrue($fmdm
    ->has('public://test-images/test-exif.jpeg'));
  $this
    ->assertTrue($fmdm
    ->has('public:///test-images/test-exif.jpeg'));
  $this
    ->assertTrue($fmdm
    ->has('public://test-images//test-exif.jpeg'));
  $this
    ->assertTrue($fmdm
    ->has('public://////test-images////test-exif.jpeg'));
  $this
    ->assertFalse($fmdm
    ->has('public:/test-images/test-exif.jpeg'));
}