function LoadTest::testMultiple
Same name in other branches
- 8.9.x core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testMultiple()
- 10 core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testMultiple()
- 11.x core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testMultiple()
This will test loading file data from the database.
File
-
core/
modules/ file/ tests/ src/ Kernel/ LoadTest.php, line 61
Class
- LoadTest
- Tests \Drupal\file\Entity\File::load().
Namespace
Drupal\Tests\file\KernelCode
public function testMultiple() {
// Create a new file entity.
$file = $this->createFile('druplicon.txt', NULL, 'public');
// Load by path.
file_test_reset();
$by_path_files = \Drupal::entityTypeManager()->getStorage('file')
->loadByProperties([
'uri' => $file->getFileUri(),
]);
$this->assertFileHookCalled('load');
$this->assertCount(1, $by_path_files, '\\Drupal::entityTypeManager()->getStorage(\'file\')->loadByProperties() 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->assertEquals($file->id(), $by_path_file->id(), 'Loading by filepath got the correct fid.');
// Load by fid.
file_test_reset();
$by_fid_files = File::loadMultiple([
$file->id(),
]);
$this->assertFileHooksCalled([]);
$this->assertCount(1, $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->assertEquals($file->getFileUri(), $by_fid_file->getFileUri(), 'Loading by fid got the correct filepath.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.