function RandomGeneratorTrait::randomString
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/RandomGeneratorTrait.php \Drupal\Tests\RandomGeneratorTrait::randomString()
- 10 core/tests/Drupal/Tests/RandomGeneratorTrait.php \Drupal\Tests\RandomGeneratorTrait::randomString()
- 9 core/tests/Drupal/Tests/RandomGeneratorTrait.php \Drupal\Tests\RandomGeneratorTrait::randomString()
- 8.9.x core/tests/Drupal/Tests/RandomGeneratorTrait.php \Drupal\Tests\RandomGeneratorTrait::randomString()
Generates a pseudo-random string of ASCII characters of codes 32 to 126.
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 \Drupal\Tests\RandomGeneratorTrait::randomMachineName(). If $length is greater than 3 the random string will include at least one ampersand ('&') and at least one greater than ('>') character to ensure coverage for special characters and avoid the introduction of random test failures.
Parameters
int $length: Length of random string to generate.
Return value
string Pseudo-randomly generated unique string including special characters.
See also
\Drupal\Component\Utility\Random::string()
115 calls to RandomGeneratorTrait::randomString()
- AreaTextTest::testAreaText in core/
modules/ views/ tests/ src/ Kernel/ Handler/ AreaTextTest.php - Tests the rendering of a text area.
- ArgumentValidatorTest::testArgumentValidateNumeric in core/
modules/ views/ tests/ src/ Kernel/ Plugin/ ArgumentValidatorTest.php - Tests numeric argument validation in a view.
- ConfigEntityTest::testCRUD in core/
modules/ config/ tests/ src/ Functional/ ConfigEntityTest.php - Tests CRUD operations.
- ConfigEntityTest::testCrudUi in core/
modules/ config/ tests/ src/ Functional/ ConfigEntityTest.php - Tests CRUD operations through the UI.
- ConfigExportImportUITest::testExportImport in core/
modules/ config/ tests/ src/ Functional/ ConfigExportImportUITest.php - Tests a simple site export import case.
File
-
core/
tests/ Drupal/ Tests/ RandomGeneratorTrait.php, line 33
Class
- RandomGeneratorTrait
- Provides random generator utility methods.
Namespace
Drupal\TestsCode
public function randomString($length = 8) : string {
return Random::string($length);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.