Skip to content
Snippets Groups Projects
Unverified Commit 329e3c7a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3042869 by claudiu.cristea, Lendude: Convert UpdateDeleteFileIfStaleTest into a Kernel test

(cherry picked from commit bdd4ddb9)
parent 0b3d688d
Branches
Tags
No related merge requests found
<?php
namespace Drupal\Tests\update\Functional;
namespace Drupal\Tests\update\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the update_delete_file_if_stale() function.
*
* @group update
*/
class UpdateDeleteFileIfStaleTest extends UpdateTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['update'];
class UpdateDeleteFileIfStaleTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
}
protected static $modules = [
'system',
'update',
];
/**
* Tests the deletion of stale files.
*/
public function testUpdateDeleteFileIfStale() {
$file_name = \Drupal::service('file_system')->saveData($this->randomMachineName(), 'public://');
$file_system = $this->container->get('file_system');
$file_name = $file_system->saveData($this->randomMachineName(), 'public://');
$this->assertNotNull($file_name);
// During testing the file change and the stale checking occurs in the same
// request, so the beginning of request will be before the file changes and
// REQUEST_TIME - $filectime is negative. Set the maximum age to a number
// even smaller than that.
// REQUEST_TIME - $filectime is negative or zero. Set the maximum age to a
// number even smaller than that.
$this->config('system.file')
->set('temporary_maximum_age', -100000)
->save();
$file_path = \Drupal::service('file_system')->realpath($file_name);
$file_path = $file_system->realpath($file_name);
update_delete_file_if_stale($file_path);
$this->assertFalse(is_file($file_path));
$this->assertFileNotExists($file_path);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment