function PasswordConfirmWidgetTest::testFillConfirmOnly

Same name in other branches
  1. 9 core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php \Drupal\Tests\user\FunctionalJavascript\PasswordConfirmWidgetTest::testFillConfirmOnly()
  2. 11.x core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php \Drupal\Tests\user\FunctionalJavascript\PasswordConfirmWidgetTest::testFillConfirmOnly()

Tests the password confirm widget so that only confirm input is filled.

1 method overrides PasswordConfirmWidgetTest::testFillConfirmOnly()
ClaroPasswordConfirmWidgetTest::testFillConfirmOnly in core/tests/Drupal/FunctionalJavascriptTests/Theme/ClaroPasswordConfirmWidgetTest.php
Tests the password confirm widget so that only confirm input is filled.

File

core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php, line 148

Class

PasswordConfirmWidgetTest
Tests the JS components added to the PasswordConfirm render element.

Namespace

Drupal\Tests\user\FunctionalJavascript

Code

public function testFillConfirmOnly() : void {
    $this->drupalGet($this->testUser
        ->toUrl('edit-form'));
    $password_confirm_widget_selector = '.js-form-type-password-confirm.js-form-item-pass';
    $password_parent_selector = '.js-form-item-pass-pass1';
    $password_confirm_selector = '.js-form-item-pass-pass2';
    $password_confirm_widget = $this->assert
        ->elementExists('css', $password_confirm_widget_selector);
    $password_confirm_item = $password_confirm_widget->find('css', $password_confirm_selector);
    $password_parent_item = $password_confirm_widget->find('css', $password_parent_selector);
    // Fill only the confirm input.
    $password_confirm_widget->fillField('Confirm password', 'o');
    // Password tips should be refreshed and get visible.
    $this->assertNotNull($this->assert
        ->waitForElement('css', "{$password_confirm_selector} + .password-suggestions > ul > li"));
    $this->assertTrue($password_confirm_item->find('css', "{$password_confirm_selector} + .password-suggestions")
        ->isVisible());
    // The appropriate strength text should appear.
    $this->assert
        ->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
    // Password match.
    $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
        ->isVisible());
    $this->assert
        ->elementContains('css', "{$password_confirm_widget_selector} {$password_confirm_selector} [data-drupal-selector='password-confirm-message']", 'Passwords match: <span data-drupal-selector="password-match-status-text" class="error">no</span>');
    // Deleting the input should hide the 'password match', but password
    // strength and tips must remain visible.
    $password_confirm_widget->fillField('Confirm password', '');
    $this->assertFalse($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
        ->isVisible());
    $this->assert
        ->elementContains('css', "{$password_confirm_widget_selector} {$password_confirm_selector} [data-drupal-selector='password-confirm-message']", 'Passwords match: <span data-drupal-selector="password-match-status-text" class="error">no</span>');
    $this->assertTrue($password_confirm_item->find('css', "{$password_confirm_selector} + .password-suggestions")
        ->isVisible());
    $this->assertTrue($password_parent_item->find('css', '.password-strength > .password-strength__meter + .password-strength__title')
        ->isVisible());
    $this->assert
        ->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
}

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