function BackupMigrateUnitTest::testGetFileInfo in Backup and Migrate 5
File
- tests/
BackupMigrateUnitTest.test, line 372
Class
- BackupMigrateUnitTest
- Unit tests for Backup and Migrate module.
Code
function testGetFileInfo() {
// this function uses _backup_migrate_temp_file because it's easy.
// is that cheating? what's the policy on relying on a previously tested function
// to run a test? answers welcome at ronan =at= gortonstudios (dot) com or the issue queue
$contents = $this
->randomName($size, '');
$valid_extensions = array(
'sql' => 'text/x-sql',
'gz' => 'application/x-gzip',
'bz' => 'application/x-bzip',
'zip' => 'application/zip',
);
$invalid_extensions = array(
'txt',
'exe',
'foo',
'',
);
foreach ($valid_extensions as $ext => $mime) {
$file = _backup_migrate_temp_file($ext);
$size = rand(10, 100);
file_put_contents($file, $this
->randomName($size, ''));
$info = _backup_migrate_file_info($file);
$this
->assertTrue(is_array($info), t('Checking that info is available on the given file (!ext)', array(
'!ext' => $ext,
)));
$this
->assertEqual($info['filesize'], $size, t('Checking that the filesize is correct'));
$this
->assertEqual($info['extension'], ".{$ext}", t('Checking that the file extension is correct'));
$this
->assertEqual($info['filename'], basename($file), t('Checking that the file basename'));
$this
->assertEqual($info['filemtime'], filemtime($file), t('Checking that modified time is correct'));
$this
->assertEqual($info['filectime'], filectime($file), t('Checking that created time is correct'));
$this
->assertEqual($info['filepath'], $file, t('Checking that file path is correct'));
$this
->assertEqual($info['filemime'], $mime, t('Checking that file mime is correct'));
}
foreach ($invalid_extensions as $ext) {
$file = _backup_migrate_temp_file($ext);
$size = rand(10, 100);
file_put_contents($file, $this
->randomName($size, ''));
$info = _backup_migrate_file_info($file);
$this
->assertFalse($info, t('Checking that info is not available on the given file'));
}
// not found file
$file = file_directory_temp() . $this
->randomName(10, '');
$info = _backup_migrate_file_info($path);
$this
->assertFalse($info, t('Checking that info is not available on the non-existent file'));
_backup_migrate_temp_file(NULL, $true);
}