annotate core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@18 1 <?php
Chris@18 2
Chris@18 3 namespace Drupal\Tests\update\Kernel;
Chris@18 4
Chris@18 5 use Drupal\KernelTests\KernelTestBase;
Chris@18 6
Chris@18 7 /**
Chris@18 8 * Tests the update_delete_file_if_stale() function.
Chris@18 9 *
Chris@18 10 * @group update
Chris@18 11 */
Chris@18 12 class UpdateDeleteFileIfStaleTest extends KernelTestBase {
Chris@18 13
Chris@18 14 /**
Chris@18 15 * {@inheritdoc}
Chris@18 16 */
Chris@18 17 protected static $modules = [
Chris@18 18 'system',
Chris@18 19 'update',
Chris@18 20 ];
Chris@18 21
Chris@18 22 /**
Chris@18 23 * Tests the deletion of stale files.
Chris@18 24 */
Chris@18 25 public function testUpdateDeleteFileIfStale() {
Chris@18 26 $file_system = $this->container->get('file_system');
Chris@18 27
Chris@18 28 $file_name = $file_system->saveData($this->randomMachineName(), 'public://');
Chris@18 29 $this->assertNotNull($file_name);
Chris@18 30
Chris@18 31 // During testing the file change and the stale checking occurs in the same
Chris@18 32 // request, so the beginning of request will be before the file changes and
Chris@18 33 // REQUEST_TIME - $filectime is negative or zero. Set the maximum age to a
Chris@18 34 // number even smaller than that.
Chris@18 35 $this->config('system.file')
Chris@18 36 ->set('temporary_maximum_age', -100000)
Chris@18 37 ->save();
Chris@18 38
Chris@18 39 $file_path = $file_system->realpath($file_name);
Chris@18 40 update_delete_file_if_stale($file_path);
Chris@18 41
Chris@18 42 $this->assertFileNotExists($file_path);
Chris@18 43 }
Chris@18 44
Chris@18 45 }