simpletest_generate_file

Versions
7
simpletest_generate_file($filename, $width, $lines, $type = 'binary-text')

Generate test file.

Code

modules/simpletest/simpletest.install, line 58

<?php
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);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.