You are here

function DrupalTestCase::randomName in SimpleTest 6

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

Generates a random string, to be used as name or whatever

Parameters

integer $number number of characters:

Return value

random string

45 calls to DrupalTestCase::randomName()
AddTopicToForum::testAddTopicToContainer in tests/forum_module.test
AddTopicToForum::testAddTopicToForum in tests/forum_module.test
AddTopicToForum::testMoveTopicToForum in tests/forum_module.test
AddTopicToForum::testMoveTopicWithCopyToForum in tests/forum_module.test
BlogAPIModuleTestCase::test_blog_API in tests/blogapi_module.test

... See full list

File

./drupal_test_case.php, line 257

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function randomName($number = 4, $prefix = 'simpletest_') {
  $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
  for ($x = 0; $x < $number; $x++) {
    $prefix .= $chars[mt_rand(0, strlen($chars) - 1)];
    if ($x == 0) {
      $chars .= '0123456789';
    }
  }
  return $prefix;
}