diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 2596212..ad82dd5 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -27,6 +27,7 @@ use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\block\Entity\Block; +use Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator; use Symfony\Component\HttpFoundation\Request; use Drupal\user\Entity\Role; @@ -527,7 +528,7 @@ protected function drupalCreateUser(array $permissions = array(), $name = NULL) // Create a user assigned to that role. $edit = array(); - $edit['name'] = !empty($name) ? $name : $this->getRandomGenerator()->string(8, TRUE, array('\Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator', 'validCharacters')); + $edit['name'] = !empty($name) ? $name : $this->getRandomGenerator()->string(8, TRUE, array($this, 'randomUsernameValidate')); $edit['mail'] = $edit['name'] . '@example.com'; $edit['pass'] = user_password(); $edit['status'] = 1; @@ -2701,4 +2702,19 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv return $request; } + + /** + * Callback for random username validation. + * + * @see \Drupal\Component\Utility\Random::string() + * + * @param string $string + * The random string to validate. + * + * @return bool + * TRUE if the random string is valid, FALSE if not. + */ + public function randomUsernameValidate($string) { + return $this->randomStringValidate($string) && !UserNameConstraintValidator::hasIllegalCharacters($string); + } } diff --git a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php index 0d99486..38f0bbf 100644 --- a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php +++ b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php @@ -65,17 +65,4 @@ public static function hasIllegalCharacters($name) { $name); } - /** - * Checks if the username has only valid characters. - * - * @param string $name - * The username to check. - * - * @return bool - * TRUE if the username has only valid characters, FALSE if not. - */ - public static function validCharacters($name) { - return !static::hasIllegalCharacters($name); - } - }