function DeleteTest::testCronDeleteNonExistingTemporary

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/DeleteTest.php \Drupal\Tests\file\Kernel\DeleteTest::testCronDeleteNonExistingTemporary()
  2. 8.9.x core/modules/file/tests/src/Kernel/DeleteTest.php \Drupal\Tests\file\Kernel\DeleteTest::testCronDeleteNonExistingTemporary()
  3. 11.x core/modules/file/tests/src/Kernel/DeleteTest.php \Drupal\Tests\file\Kernel\DeleteTest::testCronDeleteNonExistingTemporary()

Tries to run cron deletion on file deleted from the file-system.

File

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

Class

DeleteTest
Tests the file delete function.

Namespace

Drupal\Tests\file\Kernel

Code

public function testCronDeleteNonExistingTemporary() : void {
  $file = $this->createFile();
  // Delete the file, but leave it in the file_managed table.
  \Drupal::service('file_system')->delete($file->getFileUri());
  $this->assertFileDoesNotExist($file->getFileUri());
  $this->assertInstanceOf(File::class, File::load($file->id()));
  // Call file_cron() to clean up the file. Make sure the changed timestamp
  // of the file is older than the system.file.temporary_maximum_age
  // configuration value.
  \Drupal::database()->update('file_managed')
    ->fields([
    'changed' => \Drupal::time()->getRequestTime() - ($this->config('system.file')
      ->get('temporary_maximum_age') + 3),
  ])
    ->condition('fid', $file->id())
    ->execute();
  \Drupal::service('cron')->run();
  $this->assertNull(File::load($file->id()), 'File was removed from the database.');
}

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