You are here

public function DeleteTest::testUnused in Drupal 9

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

Tries deleting a normal file (as opposed to a directory, symlink, etc).

File

core/modules/file/tests/src/Kernel/DeleteTest.php, line 18

Class

DeleteTest
Tests the file delete function.

Namespace

Drupal\Tests\file\Kernel

Code

public function testUnused() {
  $file = $this
    ->createFile();

  // Check that deletion removes the file and database record.
  $this
    ->assertFileExists($file
    ->getFileUri());
  $file
    ->delete();
  $this
    ->assertFileHooksCalled([
    'delete',
  ]);
  $this
    ->assertFileDoesNotExist($file
    ->getFileUri());
  $this
    ->assertNull(File::load($file
    ->id()), 'File was removed from the database.');
}