function UserAccountFormFieldsTest::testUserRegistrationForm

Same name in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserAccountFormFieldsTest.php \Drupal\Tests\user\Kernel\UserAccountFormFieldsTest::testUserRegistrationForm()
  2. 10 core/modules/user/tests/src/Kernel/UserAccountFormFieldsTest.php \Drupal\Tests\user\Kernel\UserAccountFormFieldsTest::testUserRegistrationForm()
  3. 11.x core/modules/user/tests/src/Kernel/UserAccountFormFieldsTest.php \Drupal\Tests\user\Kernel\UserAccountFormFieldsTest::testUserRegistrationForm()

Tests the user registration form.

File

core/modules/user/tests/src/Kernel/UserAccountFormFieldsTest.php, line 48

Class

UserAccountFormFieldsTest
Verifies that the field order in user account forms is compatible with password managers of web browsers.

Namespace

Drupal\Tests\user\Kernel

Code

public function testUserRegistrationForm() {
    // Install default configuration; required for AccountFormController.
    $this->installConfig([
        'user',
    ]);
    // Disable email confirmation to unlock the password field.
    $this->config('user.settings')
        ->set('verify_mail', FALSE)
        ->save();
    $form = $this->buildAccountForm('register');
    // Verify name and pass field order.
    $this->assertFieldOrder($form['account']);
    // Verify that web browsers may autocomplete the email value and
    // autofill/prefill the name and pass values.
    foreach ([
        'mail',
        'name',
        'pass',
    ] as $key) {
        $this->assertFalse(isset($form['account'][$key]['#attributes']['autocomplete']), "'{$key}' field: 'autocomplete' attribute not found.");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.