You are here

public function UnsavedUserFieldAccessTest::testUserCreate in User protect 8

Tests if userprotect doesn't interfere with creating users.

File

tests/src/Functional/UnsavedUserFieldAccessTest.php, line 37

Class

UnsavedUserFieldAccessTest
Tests field access for an unsaved user.

Namespace

Drupal\Tests\userprotect\Functional

Code

public function testUserCreate() {

  // Create an account using the user interface.
  $name = $this
    ->randomMachineName();
  $edit = [
    'name' => $name,
    'mail' => $this
      ->randomMachineName() . '@example.com',
    'pass[pass1]' => $pass = $this
      ->randomString(),
    'pass[pass2]' => $pass,
    'notify' => FALSE,
  ];
  $this
    ->drupalPostForm('admin/people/create', $edit, t('Create new account'));
  $this
    ->assertSession()
    ->pageTextContains(t('Created a new user account for @name. No email has been sent.', [
    '@name' => $edit['name'],
  ]), 'User created');

  // Try to create an user with the same name and assert that it doesn't
  // result into a fatal error.
  $edit = [
    'name' => $name,
    'mail' => $this
      ->randomMachineName() . '@example.com',
    'pass[pass1]' => $pass = $this
      ->randomString(),
    'pass[pass2]' => $pass,
    'notify' => FALSE,
  ];
  $this
    ->drupalPostForm('admin/people/create', $edit, t('Create new account'));
  $this
    ->assertSession()
    ->pageTextContains(t('The username @name is already taken.', [
    '@name' => $edit['name'],
  ]));
}