You are here

function LoadTest::testMultiple in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/LoadTest.php \Drupal\file\Tests\LoadTest::testMultiple()

This will test loading file data from the database.

File

core/modules/file/src/Tests/LoadTest.php, line 64
Contains \Drupal\file\Tests\LoadTest.

Class

LoadTest
Tests \Drupal\file\Entity\File::load().

Namespace

Drupal\file\Tests

Code

function testMultiple() {

  // Create a new file entity.
  $file = $this
    ->createFile('druplicon.txt', NULL, 'public');

  // Load by path.
  file_test_reset();
  $by_path_files = entity_load_multiple_by_properties('file', array(
    'uri' => $file
      ->getFileUri(),
  ));
  $this
    ->assertFileHookCalled('load');
  $this
    ->assertEqual(1, count($by_path_files), 'entity_load_multiple_by_properties() returned an array of the correct size.');
  $by_path_file = reset($by_path_files);
  $this
    ->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
  $this
    ->assertEqual($by_path_file
    ->id(), $file
    ->id(), 'Loading by filepath got the correct fid.', 'File');

  // Load by fid.
  file_test_reset();
  $by_fid_files = File::loadMultiple(array(
    $file
      ->id(),
  ));
  $this
    ->assertFileHooksCalled(array());
  $this
    ->assertEqual(1, count($by_fid_files), '\\Drupal\\file\\Entity\\File::loadMultiple() returned an array of the correct size.');
  $by_fid_file = reset($by_fid_files);
  $this
    ->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
  $this
    ->assertEqual($by_fid_file
    ->getFileUri(), $file
    ->getFileUri(), 'Loading by fid got the correct filepath.', 'File');
}