You are here

public function FileFieldTestBase::assertFileEntryExists in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::assertFileEntryExists()
  2. 9 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::assertFileEntryExists()

Asserts that a file exists in the database.

File

core/modules/file/tests/src/Functional/FileFieldTestBase.php, line 222

Class

FileFieldTestBase
Provides methods specifically for testing File module's field handling.

Namespace

Drupal\Tests\file\Functional

Code

public function assertFileEntryExists($file, $message = NULL) {
  $this->container
    ->get('entity_type.manager')
    ->getStorage('file')
    ->resetCache();
  $db_file = File::load($file
    ->id());
  $message = $message ?? new FormattableMarkup('File %file exists in database at the correct path.', [
    '%file' => $file
      ->getFileUri(),
  ]);
  $this
    ->assertEquals($file
    ->getFileUri(), $db_file
    ->getFileUri(), $message);
}