function DrupalTestCase::randomName

Generates a random string containing letters and numbers.

The string will always start with a letter. The letters may be upper or lower case. This method is better for restricted inputs that do not accept certain characters. For example, when testing input fields that require machine readable values (i.e. without spaces and non-standard characters) this method is best.

Do not use this method when testing unvalidated user input. Instead, use DrupalWebTestCase::randomString().

Parameters

$length: Length of random string to generate.

Return value

Randomly generated string.

See also

DrupalWebTestCase::randomString()

177 calls to DrupalTestCase::randomName()
BlogTestCase::verifyBlogs in modules/blog/blog.test
Verify the logged in user has the desired access to the various blog nodes.
BootstrapGetFilenameTestCase::testDrupalGetFilename in modules/simpletest/tests/bootstrap.test
Test that drupal_get_filename() works correctly when the file is not found in the database.
BootstrapGetFilenameWebTestCase::testDrupalGetFilename in modules/simpletest/tests/bootstrap.test
Test that drupal_get_filename() works correctly with a full Drupal site.
BootstrapGetFilenameWebTestCase::testRecursiveRebuilds in modules/simpletest/tests/bootstrap.test
Test that drupal_get_filename() does not break recursive rebuilds.
BootstrapGetFilenameWebTestCase::testWatchdog in modules/simpletest/tests/bootstrap.test
Test that watchdog messages about missing files are correctly recorded.

... See full list

File

modules/simpletest/drupal_web_test_case.php, line 685

Class

DrupalTestCase
Base class for Drupal tests.

Code

public static function randomName($length = 8) {
  $values = array_merge(range(65, 90), range(97, 122), range(48, 57));
  $max = count($values) - 1;
  $str = chr(mt_rand(97, 122));
  for ($i = 1; $i < $length; $i++) {
    $str .= chr($values[mt_rand(0, $max)]);
  }
  return $str;
}

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