You are here

public static function DrupalTestCase::randomName in SimpleTest 7

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.2 drupal_web_test_case.php \DrupalTestCase::randomName()

Generates a random string containing letters and numbers.

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 (ie without spaces and non-standard characters) this method is best.

Parameters

$length: Length of random string to generate which will be appended to $db_prefix.

Return value

Randomly generated string.

55 calls to DrupalTestCase::randomName()
ActionsConfigurationTestCase::testActionConfiguration in tests/actions.test
Test the configuration of advanced actions through the administration interface.
BootstrapVariableTestCase::testVariable in tests/bootstrap.test
testVariable
BrowserBackendTestCase::testBrowserBackend in tests/browser.test
Test stream and curl backends execution of GET and POST requests.
CacheClearCase::setUp in tests/cache.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
CacheGetMultipleUnitTest::testCacheMultiple in tests/cache.test
Test cache_get_multiple().

... See full list

File

./drupal_web_test_case.php, line 502

Class

DrupalTestCase
Base class for Drupal tests.

Code

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