function DrupalTestCase::randomString
Generates a random string of ASCII characters of codes 32 to 126.
The generated string includes alpha-numeric characters and common miscellaneous characters. Use this method when testing general input where the content is not restricted.
Do not use this method when special characters are not possible (e.g., in machine or file names that have already been validated); instead, use DrupalWebTestCase::randomName().
Parameters
$length: Length of random string to generate.
Return value
Randomly generated string.
See also
DrupalWebTestCase::randomName()
7 calls to DrupalTestCase::randomString()
- ContactSitewideTestCase::testAutoReply in modules/
contact/ contact.test - Tests auto-reply on the site-wide contact form.
- DrupalHTTPRequestTestCase::testDrupalHTTPRequest in modules/
simpletest/ tests/ common.test - FieldTranslationsTestCase::setUp in modules/
field/ tests/ field.test - FormsTestCase::testRequiredCheckboxesRadio in modules/
simpletest/ tests/ form.test - Tests validation for required checkbox, select, and radio elements.
- FormsTestCase::testRequiredTextfieldNoTitle in modules/
simpletest/ tests/ form.test - Tests validation for required textfield element without title.
File
-
modules/
simpletest/ drupal_web_test_case.php, line 657
Class
- DrupalTestCase
- Base class for Drupal tests.
Code
public static function randomString($length = 8) {
$str = '';
for ($i = 0; $i < $length; $i++) {
$str .= chr(mt_rand(32, 126));
}
return $str;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.