public static function TestBase::randomString

Generates a random string of ASCII characters of codes 32 to 126.

The generated string includes alpha-numeric characters and common miscellaneous characters. Use this method when testing general input where the content is not restricted.

Do not use this method when special characters are not possible (e.g., in machine or file names that have already been validated); instead, use Drupal\simpletest\TestBase::randomName().

Parameters

$length: Length of random string to generate.

Return value

Randomly generated string.

See also

Drupal\simpletest\TestBase::randomName()

42 calls to TestBase::randomString()
AreaTest::testRenderArea in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php
Tests the rendering of an area.
AreaTextTest::testAreaText in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php
ArgumentNullTest::testAreaText in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/ArgumentNullTest.php
ArgumentValidatorTest::testArgumentValidateNumeric in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/ArgumentValidatorTest.php
BlockLanguageTest::testLanguageBlockVisibility in drupal/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
Tests the visibility settings for the blocks based on language.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php, line 1106
Definition of Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

public static function randomString($length = 8) {
  $str = '';
  for ($i = 0; $i < $length; $i++) {
    $str .= chr(mt_rand(32, 126));
  }
  return $str;
}