annotate core/modules/update/tests/src/Functional/UpdateDeleteFileIfStaleTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\update\Functional;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Tests the update_delete_file_if_stale() function.
Chris@0 7 *
Chris@0 8 * @group update
Chris@0 9 */
Chris@0 10 class UpdateDeleteFileIfStaleTest extends UpdateTestBase {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Modules to enable.
Chris@0 14 *
Chris@0 15 * @var array
Chris@0 16 */
Chris@0 17 public static $modules = ['update'];
Chris@0 18
Chris@0 19 /**
Chris@0 20 * {@inheritdoc}
Chris@0 21 */
Chris@0 22 protected function setUp() {
Chris@0 23 parent::setUp();
Chris@0 24 }
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Tests the deletion of stale files.
Chris@0 28 */
Chris@0 29 public function testUpdateDeleteFileIfStale() {
Chris@0 30 $file_name = file_unmanaged_save_data($this->randomMachineName());
Chris@0 31 $this->assertNotNull($file_name);
Chris@0 32
Chris@0 33 // During testing the file change and the stale checking occurs in the same
Chris@0 34 // request, so the beginning of request will be before the file changes and
Chris@0 35 // REQUEST_TIME - $filectime is negative. Set the maximum age to a number
Chris@0 36 // even smaller than that.
Chris@0 37 $this->config('system.file')
Chris@0 38 ->set('temporary_maximum_age', -100000)
Chris@0 39 ->save();
Chris@0 40
Chris@0 41 $file_path = \Drupal::service('file_system')->realpath($file_name);
Chris@0 42 update_delete_file_if_stale($file_path);
Chris@0 43
Chris@0 44 $this->assertFalse(is_file($file_path));
Chris@0 45 }
Chris@0 46
Chris@0 47 }