You are here

public function RandomGeneratorTrait::randomStringValidate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/RandomGeneratorTrait.php \Drupal\simpletest\RandomGeneratorTrait::randomStringValidate()

Callback for random string validation.

Parameters

string $string: The random string to validate.

Return value

bool TRUE if the random string is valid, FALSE if not.

See also

\Drupal\Component\Utility\Random::string()

File

core/modules/simpletest/src/RandomGeneratorTrait.php, line 68
Contains \Drupal\simpletest\RandomGeneratorTrait.

Class

RandomGeneratorTrait
Provides random generator utility methods.

Namespace

Drupal\simpletest

Code

public function randomStringValidate($string) {

  // Consecutive spaces causes issues for
  // \Drupal\simpletest\WebTestBase::assertLink().
  if (preg_match('/\\s{2,}/', $string)) {
    return FALSE;
  }

  // Starting or ending with a space means that length might not be what is
  // expected.
  if (preg_match('/^\\s|\\s$/', $string)) {
    return FALSE;
  }
  return TRUE;
}