1.20.x backdrop_web_test_case.php | protected BackdropWebTestCase::backdropGetTestFiles($type, $size = NULL) |
Get a list files that can be used in tests.
Parameters
$type: File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'.
$size: File size in bytes to match. Please check the tests/files folder.
Return value
List of files that match filter.:
File
- modules/
simpletest/ backdrop_web_test_case.php, line 1240
Class
- BackdropWebTestCase
- Test case for typical Backdrop tests.
Code
protected function backdropGetTestFiles($type, $size = NULL) {
$files = array();
// Make sure type is valid.
if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) {
if (!in_array($type, $this->generatedTestFiles)) {
switch ($type) {
case 'binary':
// Generate binary test files.
$lines = array(64, 1024);
$count = 0;
foreach ($lines as $line) {
simpletest_generate_file('binary-' . $count++, 64, $line, 'binary');
}
$this->generatedTestFiles[] = 'binary';
break;
case 'text':
// Generate text test files.
$lines = array(16, 256, 1024, 2048, 20480);
$count = 0;
foreach ($lines as $line) {
simpletest_generate_file('text-' . $count++, 64, $line, 'text');
}
$this->generatedTestFiles[] = 'text';
break;
default:
// Copy other test files from simpletest.
$original = backdrop_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '/' . $type . '-.*/');
foreach ($files as $file) {
file_unmanaged_copy($file->uri, config_get('system.core', 'file_public_path'));
}
$this->generatedTestFiles[] = $type;
break;
}
}
$files = file_scan_directory('public://', '/' . $type . '\-.*/');
// If size is set then remove any files that are not of that size.
if ($size !== NULL) {
foreach ($files as $file) {
$stats = stat($file->uri);
if ($stats['size'] != $size) {
unset($files[$file->uri]);
}
}
}
}
usort($files, array($this, 'backdropCompareFiles'));
return $files;
}