public static function TestBase::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 Drupal\simpletest\TestBase::randomString().

Parameters

$length: Length of random string to generate.

Return value

Randomly generated string.

See also

Drupal\simpletest\TestBase::randomString()

561 calls to TestBase::randomName()
ActionUnitTest::testOperations in drupal/core/modules/system/lib/Drupal/system/Tests/Action/ActionUnitTest.php
Tests the functionality of test actions.
AddFeedTest::testBasicFeedAddNoTitle in drupal/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
Tests drupal_add_feed() with paths, URLs, and titles.
AggregatorTestBase::createSampleNodes in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php
Creates sample article nodes.
AggregatorTestBase::getFeedEditArray in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php
Returns a randomly generated feed edit array.
AggregatorTestBase::getFeedEditObject in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php
Returns a randomly generated feed edit object.

... See full list

File

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

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

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;
}