| 1 file.test | public FileUnitTestCase::testFileKeepTimestamp() |
Test keeping timestamp by property in file_save().
File
- core/
modules/ file/ tests/ file.test, line 2454 - Tests for file.module.
Class
- FileUnitTestCase
- Tests basic file entity functionality.
Code
public function testFileKeepTimestamp() {
$file = $this->getTestFile('text');
$file->uid = 1;
$file->status = FILE_STATUS_PERMANENT;
/** @var File $file */
$file = entity_create('file', (array) $file);
file_save($file);
// Directly make this file "old".
$date = new DateTime('1 week ago');
$old_timestamp = (int) $date->format('U');
db_update('file_managed')
->fields(array('timestamp' => $old_timestamp))
->condition('fid', $file->fid)
->execute();
entity_get_controller('file')->resetCache();
$file = file_load($file->fid);
$this->assertEqual($file->timestamp, $old_timestamp, 'File has the old timestamp set');
$file->keepTimestamp = TRUE;
file_save($file);
$this->assertEqual($file->timestamp, $old_timestamp, 'Setting keepTimestamp to TRUE prevents updating the timestamp.');
// Load fresh with default keepTimestamp value.
$file = file_load($file->fid);
file_save($file);
$this->assertEqual($file->timestamp, REQUEST_TIME, 'Default value of keepTimestamp lets the timestamp update.');
}