You are here

public static function ThemeTest::generateFile in Image Lazyloader 8

Generates a file.

Parameters

string $filename: The filename.

int $width: The width.

int $lines: The number of lines.

string $type: The type.

Return value

string The filename of the generated file.

1 call to ThemeTest::generateFile()
ThemeTest::getTestFiles in tests/src/Kernel/ThemeTest.php
Gets a list of files that can be used in tests.

File

tests/src/Kernel/ThemeTest.php, line 259

Class

ThemeTest
Tests Lazyloaders theme integration.

Namespace

Drupal\Tests\lazyloader\Kernel

Code

public static function generateFile($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.
  $filename = 'public://' . $filename . '.txt';
  file_put_contents($filename, $text);
  return $filename;
}