public static function DrupalTestCase::randomName
7.x drupal_web_test_case.php | public static DrupalTestCase::randomName($length = 8) |
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()
363 calls to DrupalTestCase::randomName()
- AccessDeniedTestCase::testAccessDenied in drupal-7.x/
modules/ system/ system.test - ActionsConfigurationTestCase::testActionConfiguration in drupal-7.x/
modules/ simpletest/ tests/ actions.test - Test the configuration of advanced actions through the administration interface.
- AggregatorTestCase::createSampleNodes in drupal-7.x/
modules/ aggregator/ aggregator.test - Creates sample article nodes.
- AggregatorTestCase::getFeedEditArray in drupal-7.x/
modules/ aggregator/ aggregator.test - Returns a randomly generated feed edit array.
- BlockCacheTestCase::testCacheGlobal in drupal-7.x/
modules/ block/ block.test - Test DRUPAL_CACHE_GLOBAL.
File
- drupal-7.x/
modules/ simpletest/ drupal_web_test_case.php, line 623
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;
}