protected function WebTestBase::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.

27 calls to WebTestBase::drupalGetTestFiles()
CommentPreviewTest::testCommentPreview in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php
Tests comment preview.
FileFieldTestBase::getTestFile in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
Retrieves a sample file of the specified type.
FileMoveTest::testNormal in drupal/core/modules/system/lib/Drupal/system/Tests/Image/FileMoveTest.php
Tests moving a randomly generated image.
FilterHtmlImageSecureTest::testImageSource in drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
Tests removal of images having a non-local source.
ImageAdminStylesTest::createSampleImage in drupal/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
Given an image style, generate an image.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 351
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

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 text test files.
    $lines = array(
      16,
      256,
      1024,
      2048,
      20480,
    );
    $count = 0;
    foreach ($lines as $line) {
      simpletest_generate_file('text-' . $count++, 64, $line);
    }

    // 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, variable_get('file_public_path', conf_path() . '/files'));
    }
    $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;
}