You are here

public function UserRegistrationTest::testUniqueFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/UserRegistrationTest.php \Drupal\user\Tests\UserRegistrationTest::testUniqueFields()

Tests username and email field constraints on user registration.

See also

\Drupal\user\Plugin\Validation\Constraint\UserNameUnique

\Drupal\user\Plugin\Validation\Constraint\UserMailUnique

File

core/modules/user/src/Tests/UserRegistrationTest.php, line 274
Contains \Drupal\user\Tests\UserRegistrationTest.

Class

UserRegistrationTest
Tests registration of user under different configurations.

Namespace

Drupal\user\Tests

Code

public function testUniqueFields() {
  $account = $this
    ->drupalCreateUser();
  $edit = [
    'mail' => 'test@example.com',
    'name' => $account
      ->getUsername(),
  ];
  $this
    ->drupalPostForm('user/register', $edit, t('Create new account'));
  $this
    ->assertRaw(SafeMarkup::format('The username %value is already taken.', [
    '%value' => $account
      ->getUsername(),
  ]));
  $edit = [
    'mail' => $account
      ->getEmail(),
    'name' => $this
      ->randomString(),
  ];
  $this
    ->drupalPostForm('user/register', $edit, t('Create new account'));
  $this
    ->assertRaw(SafeMarkup::format('The email address %value is already taken.', [
    '%value' => $account
      ->getEmail(),
  ]));
}