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

Generate test file.

File

modules/simpletest/simpletest.module, line 449
Provides testing functionality.

Code

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

  for ($i = 0; $i < $lines; $i++) {
    // Generate $width - 1 characters to leave space for the "\n" character.
    if (empty($line)) {
      for ($j = 0; $j < $width - 1; $j++) {
        switch ($type) {
          case 'text':
            $line .= chr(rand(32, 126));
            break;
          case 'binary':
            $line .= chr(rand(0, 31));
            break;
          case 'binary-text':
          default:
            $line .= rand(0, 1);
            break;
        }
      }
      $line .= "\n";
    }
    $text .= $line;
  }

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