public function LoadTest::testMultiple in Drupal 10
Same name and namespace in other branches
- 8 core/modules/file/tests/src/Kernel/LoadTest.php \Drupal\Tests\file\Kernel\LoadTest::testMultiple()
- 9 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.');
}