function simpletest_generate_file

7.x simpletest.module simpletest_generate_file($filename, $width, $lines, $type = 'binary-text')

Generate test file.

1 call to simpletest_generate_file()
DrupalWebTestCase::drupalGetTestFiles in drupal-7.x/modules/simpletest/drupal_web_test_case.php
Get a list files that can be used in tests.

File

drupal-7.x/modules/simpletest/simpletest.module, line 489
Provides testing functionality.

Code

function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
  $size = $width * $lines - $lines;

  // Generate random text
  $text = '';
  for ($i = 0; $i < $size; $i++) {
    switch ($type) {
      case 'text':
        $text .= chr(rand(32, 126));
        break;
      case 'binary':
        $text .= chr(rand(0, 31));
        break;
      case 'binary-text':
      default:
        $text .= rand(0, 1);
        break;
    }
  }
  $text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symmetrical file.

  // Create filename.
  file_put_contents('public://' . $filename . '.txt', $text);
  return $filename;
}