You are here

function simpletest_generate_file in SimpleTest 7

Same name and namespace in other branches
  1. 8.3 simpletest.module \simpletest_generate_file()
  2. 6.2 simpletest.module \simpletest_generate_file()
  3. 7.2 simpletest.module \simpletest_generate_file()

Generate test file.

1 call to simpletest_generate_file()
simpletest_install in ./simpletest.install
Implement hook_install().

File

./simpletest.install, line 58
Install, update and uninstall functions for the simpletest module.

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 symetrical file.
  // Create filename.
  $path = file_directory_path() . '/simpletest/';
  $count = simpletest_get_file_count($path, $filename);
  file_put_contents($path . $filename . '-' . ($count + 1) . '.txt', $text);
}