protected function WebTestBase::drupalGetTestFiles in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::drupalGetTestFiles()
Gets a list of files that can be used in tests.
The first time this method is called, it will call simpletest_generate_file() to generate binary and ASCII text files in the public:// directory. It will also copy all files in core/modules/simpletest/files to public://. These contain image, SQL, PHP, JavaScript, and HTML files.
All filenames are prefixed with their type and have appropriate extensions:
- text-*.txt
- binary-*.txt
- html-*.html and html-*.txt
- image-*.png, image-*.jpg, and image-*.gif
- javascript-*.txt and javascript-*.script
- php-*.txt and php-*.php
- sql-*.txt and sql-*.sql
Any subsequent calls will not generate any new files, or copy the files over again. However, if a test class adds a new file to public:// that is prefixed with one of the above types, it will get returned as well, even on subsequent calls.
Parameters
$type: File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'.
$size: (optional) File size in bytes to match. Defaults to NULL, which will not filter the returned list by size.
Return value
List of files in public:// that match the filter(s).
40 calls to WebTestBase::drupalGetTestFiles()
- CommentPreviewTest::testCommentPreview in core/
modules/ comment/ src/ Tests/ CommentPreviewTest.php - Tests comment preview.
- ConfigImportUploadTest::testImport in core/
modules/ config/ src/ Tests/ ConfigImportUploadTest.php - Tests importing configuration.
- ContentTranslationSyncImageTest::setUp in core/
modules/ content_translation/ src/ Tests/ ContentTranslationSyncImageTest.php - Sets up a Drupal site for running functional and integration tests.
- EntityReferenceFileUploadTest::testFileUpload in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFileUploadTest.php - Tests that the autocomplete input element does not cause ajax fatal.
- FileFieldDisplayTest::testDescToggle in core/
modules/ file/ src/ Tests/ FileFieldDisplayTest.php - Tests description toggle for field instance configuration.
File
- core/
modules/ simpletest/ src/ WebTestBase.php, line 513 - Contains \Drupal\simpletest\WebTestBase.
Class
- WebTestBase
- Test case for typical Drupal tests.
Namespace
Drupal\simpletestCode
protected function drupalGetTestFiles($type, $size = NULL) {
if (empty($this->generatedTestFiles)) {
// Generate binary test files.
$lines = array(
64,
1024,
);
$count = 0;
foreach ($lines as $line) {
simpletest_generate_file('binary-' . $count++, 64, $line, 'binary');
}
// Generate ASCII text test files.
$lines = array(
16,
256,
1024,
2048,
20480,
);
$count = 0;
foreach ($lines as $line) {
simpletest_generate_file('text-' . $count++, 64, $line, 'text');
}
// Copy other test files from simpletest.
$original = drupal_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
foreach ($files as $file) {
file_unmanaged_copy($file->uri, PublicStream::basePath());
}
$this->generatedTestFiles = TRUE;
}
$files = array();
// Make sure type is valid.
if (in_array($type, array(
'binary',
'html',
'image',
'javascript',
'php',
'sql',
'text',
))) {
$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,
'drupalCompareFiles',
));
return $files;
}