protected function FlagCreateTrait::randomHTMLString in Flag 8.4
Generates an HTML-safe random string.
To generate strings which can be located in FunctionalJavascript tests. In tests using 'css' queries that use the 'contains()' selector we need to remove all white space characters.
Parameters
int $length: The length of the string to generate.
Return value
string A random string of HTML-safe characters.
3 calls to FlagCreateTrait::randomHTMLString()
- FlagContextualLinksTest::setUp in tests/
src/ FunctionalJavascript/ FlagContextualLinksTest.php - FlagCreateTrait::createFlagFromArray in tests/
src/ Traits/ FlagCreateTrait.php - Creates a flag from an array.
- FlagTestBase::createFlagWithForm in tests/
src/ Functional/ FlagTestBase.php - Creates a flag entity using the admin UI.
File
- tests/
src/ Traits/ FlagCreateTrait.php, line 196
Class
- FlagCreateTrait
- Trait for programmatically creating Flags.
Namespace
Drupal\Tests\flag\TraitsCode
protected function randomHTMLString($length = 8) {
// A safe string.
$str = Html::decodeEntities(Xss::filter($this
->randomString($length * 2), []));
// Remove all whitespaces.
$no_space = preg_replace('/\\s+/', '', $str);
// Remove all angle brackets.
$no_brackets = preg_replace('/[<>]/', '_', $no_space);
// Trim to the required length.
return substr($no_brackets, 0, $length);
}