You are here

protected function DrupalWebTestCase::drupalGetTestFiles in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::drupalGetTestFiles()
  2. 7.2 drupal_web_test_case.php \DrupalWebTestCase::drupalGetTestFiles()

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.

2 calls to DrupalWebTestCase::drupalGetTestFiles()
FileSaveUploadTest::setUp in tests/file.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
FileSaveUploadTest::testNormal in tests/file.test
Test the file_save_upload() function.

File

./drupal_web_test_case.php, line 807

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function drupalGetTestFiles($type, $size = NULL) {
  $files = array();

  // Make sure type is valid.
  if (in_array($type, array(
    'binary',
    'html',
    'image',
    'javascript',
    'php',
    'sql',
    'text',
  ))) {

    // Use original file directory instead of one created during setUp().
    $path = $this->originalFileDirectory . '/simpletest';
    $files = file_scan_directory($path, '/' . $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;
}