You are here

public function LoadTest::testSingleValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testSingleValues()

Load a single file and ensure that the correct values are returned.

File

core/modules/file/tests/src/Kernel/LoadTest.php, line 44

Class

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

Namespace

Drupal\Tests\file\Kernel

Code

public function testSingleValues() {

  // Create a new file entity from scratch so we know the values.
  $file = $this
    ->createFile('druplicon.txt', NULL, 'public');
  $by_fid_file = File::load($file
    ->id());
  $this
    ->assertFileHookCalled('load');
  $this
    ->assertIsObject($by_fid_file);
  $this
    ->assertEquals($file
    ->id(), $by_fid_file
    ->id(), 'Loading by fid got the same fid.');
  $this
    ->assertEquals($file
    ->getFileUri(), $by_fid_file
    ->getFileUri(), 'Loading by fid got the correct filepath.');
  $this
    ->assertEquals($file
    ->getFilename(), $by_fid_file
    ->getFilename(), 'Loading by fid got the correct filename.');
  $this
    ->assertEquals($file
    ->getMimeType(), $by_fid_file
    ->getMimeType(), 'Loading by fid got the correct MIME type.');
  $this
    ->assertEquals($file
    ->isPermanent(), $by_fid_file
    ->isPermanent(), 'Loading by fid got the correct status.');
  $this
    ->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
}