summaryrefslogtreecommitdiff
path: root/modules/system/system.test
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-12-28 19:11:31 +0000
committerDries Buytaert <dries@buytaert.net>2008-12-28 19:11:31 +0000
commit53b83cdcb99531a73765f31301a8dba2d9d0252c (patch)
tree96d5141470fd77226ca772a321f42ad4c421a178 /modules/system/system.test
parent48673b7506cadf7754b6e047b1fd9e77f3e8fea4 (diff)
downloadbrdo-53b83cdcb99531a73765f31301a8dba2d9d0252c.tar.gz
brdo-53b83cdcb99531a73765f31301a8dba2d9d0252c.tar.bz2
- Patch #330633 by drewish: temporary file clean-up _and_ unit tests. Oh yeah.
Diffstat (limited to 'modules/system/system.test')
-rw-r--r--modules/system/system.test35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/system/system.test b/modules/system/system.test
index f07d8707e..64e8a6f03 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -252,6 +252,41 @@ class CronRunTestCase extends DrupalWebTestCase {
// Execute cron directly.
$this->assertTrue(drupal_cron_run(), t('Cron ran successfully.'));
}
+
+ /**
+ * Ensure that temporary files are removed.
+ */
+ function testTempFileCleanup() {
+ // Create files for all the possible combinations of age and status. We're
+ // using UPDATE statments rather than file_save() because it would set the
+ // timestamp.
+
+ // Temporary file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
+ $temp_old = file_save_data('');
+ db_query('UPDATE {files} SET status = :status, timestamp = :timestamp WHERE fid = :fid', array(':status' => FILE_STATUS_TEMPORARY, ':timestamp' => 1, ':fid' => $temp_old->fid));
+ $this->assertTrue(file_exists($temp_old->filepath), t('Old temp file was created correctly.'));
+
+ // Temporary file that is less than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
+ $temp_new = file_save_data('');
+ db_query('UPDATE {files} SET status = :status WHERE fid = :fid', array(':status' => FILE_STATUS_TEMPORARY, ':fid' => $temp_new->fid));
+ $this->assertTrue(file_exists($temp_new->filepath), t('New temp file was created correctly.'));
+
+ // Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
+ $perm_old = file_save_data('');
+ db_query('UPDATE {files} SET timestamp = :timestamp WHERE fid = :fid', array(':timestamp' => 1, ':fid' => $perm_old->fid));
+ $this->assertTrue(file_exists($perm_old->filepath), t('Old permanent file was created correctly.'));
+
+ // Permanent file that is newer than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
+ $perm_new = file_save_data('');
+ $this->assertTrue(file_exists($perm_new->filepath), t('New permanent file was created correctly.'));
+
+ // Run cron and then ensure that only the old, temp file was deleted.
+ $this->assertTrue(drupal_cron_run(), t('Cron ran successfully.'));
+ $this->assertFalse(file_exists($temp_old->filepath), t('Old temp file was correctly removed.'));
+ $this->assertTrue(file_exists($temp_new->filepath), t('New temp file was correctly ignored.'));
+ $this->assertTrue(file_exists($perm_old->filepath), t('Old permanent file was correctly ignored.'));
+ $this->assertTrue(file_exists($perm_new->filepath), t('New permanent file was correctly ignored.'));
+ }
}
class AdminOverviewTestCase extends DrupalWebTestCase {