You are here

public static function DrupalTestCase::randomName in SimpleTest 7.2

Same name and namespace in other branches
  1. 5 drupal_test_case.php \DrupalTestCase::randomName()
  2. 6.2 drupal_web_test_case.php \DrupalTestCase::randomName()
  3. 6 drupal_test_case.php \DrupalTestCase::randomName()
  4. 7 drupal_web_test_case.php \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.

Parameters

$length: Length of random string to generate.

Return value

Randomly generated string.

6 calls to DrupalTestCase::randomName()
DrupalRemoteTestCase::randomName in ./drupal_web_test_case.php
Add remote prefix.
DrupalWebTestCase::drupalCreateContentType in ./drupal_web_test_case.php
Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode in ./drupal_web_test_case.php
Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole in ./drupal_web_test_case.php
Internal helper function; Create a role with specified permissions.
DrupalWebTestCase::drupalCreateUser in ./drupal_web_test_case.php
Create a user with a given set of permissions. The permissions correspond to the names given on the privileges page.

... See full list

1 method overrides DrupalTestCase::randomName()
DrupalRemoteTestCase::randomName in ./drupal_web_test_case.php
Add remote prefix.

File

./drupal_web_test_case.php, line 576
Provides DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase classes.

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