function LoadTest::testSingleValues

Same name in other branches
  1. 9 core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testSingleValues()
  2. 8.9.x core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testSingleValues()
  3. 10 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 46

Class

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

Namespace

Drupal\Tests\file\Kernel

Code

public function testSingleValues() : void {
    // 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.