function UsageTest::createTempFiles in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/UsageTest.php \Drupal\file\Tests\UsageTest::createTempFiles()
Create files for all the possible combinations of age and status.
We are using UPDATE statements because using the API would set the timestamp.
3 calls to UsageTest::createTempFiles()
- UsageTest::testTempFileCleanupDefault in core/
modules/ file/ src/ Tests/ UsageTest.php - Ensure that temporary files are removed by default.
- UsageTest::testTempFileCustomCleanup in core/
modules/ file/ src/ Tests/ UsageTest.php - Ensure that temporary files are kept as configured.
- UsageTest::testTempFileNoCleanup in core/
modules/ file/ src/ Tests/ UsageTest.php - Ensure that temporary files are kept as configured.
File
- core/
modules/ file/ src/ Tests/ UsageTest.php, line 125 - Contains \Drupal\file\Tests\UsageTest.
Class
- UsageTest
- Tests file usage functions.
Namespace
Drupal\file\TestsCode
function createTempFiles() {
// Temporary file that is old.
$temp_old = file_save_data('');
db_update('file_managed')
->fields(array(
'status' => 0,
'changed' => REQUEST_TIME - $this
->config('system.file')
->get('temporary_maximum_age') - 1,
))
->condition('fid', $temp_old
->id())
->execute();
$this
->assertTrue(file_exists($temp_old
->getFileUri()), 'Old temp file was created correctly.');
// Temporary file that is new.
$temp_new = file_save_data('');
db_update('file_managed')
->fields(array(
'status' => 0,
))
->condition('fid', $temp_new
->id())
->execute();
$this
->assertTrue(file_exists($temp_new
->getFileUri()), 'New temp file was created correctly.');
// Permanent file that is old.
$perm_old = file_save_data('');
db_update('file_managed')
->fields(array(
'changed' => REQUEST_TIME - $this
->config('system.file')
->get('temporary_maximum_age') - 1,
))
->condition('fid', $temp_old
->id())
->execute();
$this
->assertTrue(file_exists($perm_old
->getFileUri()), 'Old permanent file was created correctly.');
// Permanent file that is new.
$perm_new = file_save_data('');
$this
->assertTrue(file_exists($perm_new
->getFileUri()), 'New permanent file was created correctly.');
return array(
$temp_old,
$temp_new,
$perm_old,
$perm_new,
);
}