function simpletest_generate_file

Same name in other branches
  1. 8.9.x core/modules/simpletest/simpletest.module \simpletest_generate_file()

Generate test file.

2 calls to simpletest_generate_file()
DrupalWebTestCase::drupalGetTestFiles in modules/simpletest/drupal_web_test_case.php
Get a list files that can be used in tests.
FileManagedFileElementTestCase::testManagedFileExceedMaximumFileSize in modules/file/tests/file.test
Tests uploading a file that exceeds the maximum file size.

File

modules/simpletest/simpletest.module, line 517

Code

function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
    $text = '';
    for ($i = 0; $i < $lines; $i++) {
        // Generate $width - 1 characters to leave space for the "\n" character.
        for ($j = 0; $j < $width - 1; $j++) {
            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 .= "\n";
    }
    // Create filename.
    file_put_contents('public://' . $filename . '.txt', $text);
    return $filename;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.