You are here

public function UserNotBlockedTest::testNotBlocked in Create user permission 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/UserNotBlockedTest.php \Drupal\Tests\create_user_permission\Functional\UserNotBlockedTest::testNotBlocked()

Test that users created are not blocked.

File

tests/src/Functional/UserNotBlockedTest.php, line 22

Class

UserNotBlockedTest
Test that newly created users can be created, unblocked.

Namespace

Drupal\Tests\create_user_permission\Functional

Code

public function testNotBlocked() {
  $values = [
    'visitors_admin_approval',
    'admin_only',
  ];
  foreach ($values as $value) {
    \Drupal::configFactory()
      ->getEditable('user.settings')
      ->set('register', $value)
      ->save();
    $create_user = $this
      ->drupalCreateUser([
      'create users',
    ]);
    $this
      ->drupalLogin($create_user);

    // Go to the add person page.
    $this
      ->drupalGet('admin/people/create');
    $testmail = 'testuser1@example.com';
    $password = 'testpassword';
    $this
      ->drupalPostForm('admin/people/create', [
      'mail' => $testmail,
      'name' => $testmail,
      'pass[pass1]' => $password,
      'pass[pass2]' => $password,
    ], t('Create new account'));

    /** @var \Drupal\user\Entity\User $user */
    $user = user_load_by_mail($testmail);
    $this
      ->assertFalse($user
      ->isBlocked());
  }
}