diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index cc5785a..2ef15fb 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\simpletest\WebTestBase; @@ -24,7 +25,7 @@ class UserRegistrationTest extends WebTestBase { */ public static $modules = array('field_test'); - function testRegistrationWithEmailVerification() { + function ptesRegistrationWithEmailVerification() { $config = $this->config('user.settings'); // Require email verification. $config->set('verify_mail', TRUE)->save(); @@ -60,7 +61,7 @@ function testRegistrationWithEmailVerification() { $this->assertFalse($new_user->isActive(), 'New account is blocked until approved by an administrator.'); } - function testRegistrationWithoutEmailVerification() { + function ptesRegistrationWithoutEmailVerification() { $config = $this->config('user.settings'); // Don't require email verification and allow registration by site visitors // without administrator approval. @@ -124,7 +125,7 @@ function testRegistrationWithoutEmailVerification() { $this->assertText(t('Member for'), 'User can log in after administrator approval.'); } - function testRegistrationEmailDuplicates() { + function ptesRegistrationEmailDuplicates() { // Don't require email verification and allow registration by site visitors // without administrator approval. $this->config('user.settings') @@ -150,7 +151,7 @@ function testRegistrationEmailDuplicates() { $this->assertText(t('The email address @email is already taken.', array('@email' => $duplicate_user->getEmail())), 'Supplying a duplicate email address with added whitespace displays an error message'); } - function testRegistrationDefaultValues() { + function ptesRegistrationDefaultValues() { // Don't require email verification and allow registration by site visitors // without administrator approval. $config_user_settings = $this->config('user.settings') @@ -193,9 +194,27 @@ function testRegistrationDefaultValues() { } /** + * Ensures that you cannot register with the same name / mail twice. + * + * @see \Drupal\user\Plugin\Validation\Constraint\UserNameUnique + * @see \Drupal\user\Plugin\Validation\Constraint\UserMailUnique + */ + public function testUniqueFields() { + $account = $this->drupalCreateUser([]); + + // Existing username. + $this->drupalPostForm('user/register', ['mail' => 'test@example.com', 'name' => $account->getUsername()], t('Create new account')); + $this->assertRaw(Safemarkup::format('The username %value is already taken.', ['%value' => $account->getUsername()])); + + // Existing mail address. + $this->drupalPostForm('user/register', ['mail' => $account->getEmail(), 'name' => $this->randomString()], t('Create new account')); + $this->assertRaw(Safemarkup::format('The email address %value is already taken.', ['%value' => $account->getEmail()])); + } + + /** * Tests Field API fields on user registration forms. */ - function testRegistrationWithUserFields() { + function ptesRegistrationWithUserFields() { // Create a field on 'user' entity type. $field_storage = entity_create('field_storage_config', array( 'field_name' => 'test_user_field',