diff --git a/core/lib/Drupal/Core/Render/Element/PasswordReveal.php b/core/lib/Drupal/Core/Render/Element/PasswordReveal.php index 2ee055b..57fe9b9 100644 --- a/core/lib/Drupal/Core/Render/Element/PasswordReveal.php +++ b/core/lib/Drupal/Core/Render/Element/PasswordReveal.php @@ -34,15 +34,15 @@ class PasswordReveal extends Password { */ public function getInfo() { $info = parent::getInfo(); - $info['#process'][] = [get_class($this), 'processPasswordConfirm']; + $info['#process'][] = [get_class($this), 'processPasswordReveal']; return $info; } /** - * Expand a password_confirm field into two text boxes. + * Adds the attributes needed to add password strength and the reveal button. */ - public static function processPasswordConfirm(&$element, FormStateInterface $form_state, &$complete_form) { + public static function processPasswordReveal(&$element, FormStateInterface $form_state, &$complete_form) { $element['#attributes']['class'][] = 'password-field'; $element['#attributes']['class'][] = 'js-password-field'; $element['#attached']['library'][] = 'core/drupal.revealpass'; diff --git a/core/modules/user/src/Tests/UserEditTest.php b/core/modules/user/src/Tests/UserEditTest.php index 07daeca..172d955 100644 --- a/core/modules/user/src/Tests/UserEditTest.php +++ b/core/modules/user/src/Tests/UserEditTest.php @@ -106,6 +106,19 @@ function testUserEdit() { $this->assertText(t('The changes have been saved.')); $this->assertNoFieldChecked('edit-status-0'); $this->assertFieldChecked('edit-status-1'); + + // Test editing the user with a password_reveal field. + $config->set('password_type_reveal', TRUE)->save(); + $config->set('password_strength', TRUE)->save(); + + $this->drupalGet("user/" . $admin_user->id() . "/edit"); + $this->assertRaw('Password strength:', 'The password strength indicator is displayed.'); + + $edit = array(); + $edit['pass'] = $this->randomMachineName(); + $edit['current_pass'] = $admin_user->pass_raw; + $this->drupalPostForm("user/" . $admin_user->id() . "/edit", $edit, t('Save')); + $this->assertRaw(t("The changes have been saved.")); } /** diff --git a/core/tests/Drupal/Tests/Core/Render/Element/PasswordRevealTest.php b/core/tests/Drupal/Tests/Core/Render/Element/PasswordRevealTest.php new file mode 100644 index 0000000..9fbffdb --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Render/Element/PasswordRevealTest.php @@ -0,0 +1,45 @@ +prophesize(FormStateInterface::class)->reveal(); + $this->assertSame($expected, PasswordReveal::valueCallback($element, $input, $form_state)); + } + + /** + * Data provider for testValueCallback(). + */ + public function providerTestValueCallback() { + $data = []; + $data[] = [NULL, FALSE]; + $data[] = [NULL, NULL]; + $data[] = ['', ['test']]; + $data[] = ['test', 'test']; + $data[] = ['123', 123]; + + return $data; + } + +}