diff --git a/core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php b/core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php index ebebcc0501..07f1c464ab 100644 --- a/core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php +++ b/core/modules/user/tests/src/FunctionalJavascript/PasswordConfirmWidgetTest.php @@ -117,8 +117,8 @@ public function testPasswordConfirmWidgetJsComponents() { // Password match message must be visible. $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')->isVisible()); - $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-confirm-text"]')->hasClass('ok')); - $this->assert->elementTextContains('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-confirm-text"]', 'yes'); + $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]')->hasClass('ok')); + $this->assert->elementTextContains('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]', 'yes'); // Password suggestions should get invisible. $this->assertFalse($password_confirm_item->find('css', "$password_confirm_selector + .password-suggestions")->isVisible()); @@ -137,7 +137,7 @@ public function testPasswordConfirmMessage() { // Password match message. $this->assertTrue($password_confirm_item->has('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')); $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", '
Passwords match:
'); + $this->assert->elementContains('css', "$password_confirm_widget_selector $password_confirm_selector", '
Passwords match:
'); } /** @@ -164,13 +164,13 @@ public function testFillConfirmOnly() { // 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: no'); + $this->assert->elementContains('css', "$password_confirm_widget_selector $password_confirm_selector [data-drupal-selector='password-confirm-message']", 'Passwords match: no'); // 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: no'); + $this->assert->elementContains('css', "$password_confirm_widget_selector $password_confirm_selector [data-drupal-selector='password-confirm-message']", 'Passwords match: no'); $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", '
Password strength: Weak
'); diff --git a/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php b/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php new file mode 100644 index 0000000000..5cf76713bd --- /dev/null +++ b/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php @@ -0,0 +1,64 @@ +assert = $this->assertSession(); + + // Create a user. + $this->testUser = $this->createUser(); + $this->drupalLogin($this->testUser); + } + + /** + * Tests password widget theme functions and its deprecations. + * + * @group legacy + * + * @expectedDeprecation Javascript Deprecation: Returning without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101 + * @expectedDeprecation Javascript Deprecation: The js-password-strength__indicator class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__indicator with a data-drupal-selector="password-strength-indicator" attribute. See https://www.drupal.org/node/3152101 + * @expectedDeprecation Javascript Deprecation: The js-password-strength__text class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__text with a data-drupal-selector="password-strength-text" attribute. See https://www.drupal.org/node/3152101 + * @expectedDeprecation Javascript Deprecation: The message property is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. The markup should be constructed using messageTips property and Drupal.theme.passwordSuggestions. See https://www.drupal.org/node/3130352 + */ + public function testPasswordConfirmWidgetJsComponents() { + $assert_session = $this->assertSession(); + + $this->drupalGet($this->testUser->toUrl('edit-form')); + + $this->assertNotNull($assert_session->waitForText('Overridden passwordStrength:')); + $assert_session->elementTextContains('css', '.password-strength__meter', 'Overridden passwordStrength:'); + $assert_session->elementTextContains('css', '.password-confirm-message', 'Overridden passwordConfirmMessage:'); + $this->getSession()->getPage()->fillField('pass[pass1]', 'a'); + $assert_session->elementTextContains('css', '.password-suggestions', 'Overridden passwordSuggestions:'); + } + +} diff --git a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js new file mode 100644 index 0000000000..add1396a20 --- /dev/null +++ b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js @@ -0,0 +1,91 @@ +/** + * @file + * Overrides password theme functions for testing. + */ + +(Drupal => { + /** + * Constructs a password strength message. + * + * @param {object} passwordSettings + * An object containing password related settings and translated text to + * display. + * @param {string} passwordSettings.strengthTitle + * The title that precedes the strength text. + * + * @return {string} + * Markup for password strength message. + */ + Drupal.theme.passwordStrength = ({ strengthTitle }) => { + const strengthIndicator = + 'Overridden passwordStrength:
'; + const strengthText = + ''; + return ` +
+
${strengthIndicator}
+
${strengthTitle} ${strengthText}
+
+ `; + }; + + /** + * Constructs password suggestions tips. + * + * @param {object} passwordSettings + * An object containing password related settings and translated text to + * display. + * @param {string} passwordSettings.hasWeaknesses + * The title that precedes tips. + * @param {Array.} tips + * Array containing the tips. + * + * @return {string} + * Markup for password suggestions. + */ + Drupal.theme.passwordSuggestions = ({ hasWeaknesses }, tips) => + `
Overridden passwordSuggestions: ${ + tips.length + ? `${hasWeaknesses}
  • ${tips.join('
  • ')}
` + : '' + }
`; + + /** + * Constructs a password confirm message element. + * + * @param {object} passwordSettings + * An object containing password related settings and translated text to + * display. + * @param {string} passwordSettings.confirmTitle + * The translated confirm description that labels the actual confirm text. + * + * @return {string} + * Markup for the password confirm message. + */ + Drupal.theme.passwordConfirmMessage = ({ confirmTitle }) => { + const confirmTextWrapper = + 'Overridden passwordConfirmMessage:'; + return `
${confirmTitle} ${confirmTextWrapper}
`; + }; + + /** + * Confirm deprecation of property in evaluatePasswordStrength() return. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches a check for the deprecated `message` property in the object + * returned by Drupal.evaluatePasswordStrength(). + */ + Drupal.behaviors.passwordThemeFunctionTest = { + attach(context, settings) { + const strength = Drupal.evaluatePasswordStrength( + 'password', + settings.password, + ); + + // eslint-disable-next-line no-unused-vars + const { message } = strength; + }, + }; +})(Drupal); diff --git a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js new file mode 100644 index 0000000000..7f45f8f50d --- /dev/null +++ b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js @@ -0,0 +1,33 @@ +/** +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ + +(function (Drupal) { + Drupal.theme.passwordStrength = function (_ref) { + var strengthTitle = _ref.strengthTitle; + var strengthIndicator = 'Overridden passwordStrength:
'; + var strengthText = ''; + return "\n
\n
".concat(strengthIndicator, "
\n
").concat(strengthTitle, " ").concat(strengthText, "
\n
\n "); + }; + + Drupal.theme.passwordSuggestions = function (_ref2, tips) { + var hasWeaknesses = _ref2.hasWeaknesses; + return "
Overridden passwordSuggestions: ".concat(tips.length ? "".concat(hasWeaknesses, "
  • ").concat(tips.join('
  • '), "
") : '', "
"); + }; + + Drupal.theme.passwordConfirmMessage = function (_ref3) { + var confirmTitle = _ref3.confirmTitle; + var confirmTextWrapper = 'Overridden passwordConfirmMessage:'; + return "
".concat(confirmTitle, " ").concat(confirmTextWrapper, "
"); + }; + + Drupal.behaviors.passwordThemeFunctionTest = { + attach: function attach(context, settings) { + var strength = Drupal.evaluatePasswordStrength('password', settings.password); + var message = strength.message; + } + }; +})(Drupal); \ No newline at end of file diff --git a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml new file mode 100644 index 0000000000..ba973fb6bc --- /dev/null +++ b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml @@ -0,0 +1,7 @@ +name: 'Password Theme Function Test theme' +type: theme +base theme: stark +description: 'Tests theme functions' +version: VERSION +libraries: + - password_theme_function_test/password-theme-functions \ No newline at end of file diff --git a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml new file mode 100644 index 0000000000..3f2b7eec22 --- /dev/null +++ b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml @@ -0,0 +1,6 @@ +password-theme-functions: + js: + js/password-theme-functions.js: {} + dependencies: + - core/drupal + - user/drupal.user diff --git a/core/modules/user/user.es6.js b/core/modules/user/user.es6.js index 7ddbc54e19..ef1ccaba99 100644 --- a/core/modules/user/user.es6.js +++ b/core/modules/user/user.es6.js @@ -81,14 +81,14 @@ Drupal.theme('passwordConfirmMessage', settings.password), ); - let $confirmTextWrapper = $passwordConfirmMessage - .find('[data-drupal-selector="password-confirm-text"]') + let $passwordMatchStatus = $passwordConfirmMessage + .find('[data-drupal-selector="password-match-status-text"]') .first(); - if ($confirmTextWrapper.length === 0) { - $confirmTextWrapper = $passwordConfirmMessage.find('span').first(); + if ($passwordMatchStatus.length === 0) { + $passwordMatchStatus = $passwordConfirmMessage.find('span').first(); Drupal.deprecationError({ message: - 'Returning without data-drupal-selector="password-confirm-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101', + 'Returning without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101', }); } @@ -202,15 +202,15 @@ // Update the success message and set the class if needed. if ( - !$confirmTextWrapper.hasClass(confirmClass) || - !$confirmTextWrapper.html() === confirmMessage + !$passwordMatchStatus.hasClass(confirmClass) || + !$passwordMatchStatus.html() === confirmMessage ) { if (confirmTextWrapperClassesToRemove) { - $confirmTextWrapper.removeClass( + $passwordMatchStatus.removeClass( confirmTextWrapperClassesToRemove, ); } - $confirmTextWrapper.html(confirmMessage).addClass(confirmClass); + $passwordMatchStatus.html(confirmMessage).addClass(confirmClass); } }; diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 58dc46fd10..b2a04a69f8 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -33,12 +33,12 @@ var $passwordWidget = $mainInput.closest('.js-form-type-password-confirm'); var $confirmInput = $passwordWidget.find('input.js-password-confirm'); var $passwordConfirmMessage = $(Drupal.theme('passwordConfirmMessage', settings.password)); - var $confirmTextWrapper = $passwordConfirmMessage.find('[data-drupal-selector="password-confirm-text"]').first(); + var $passwordMatchStatus = $passwordConfirmMessage.find('[data-drupal-selector="password-match-status-text"]').first(); - if ($confirmTextWrapper.length === 0) { - $confirmTextWrapper = $passwordConfirmMessage.find('span').first(); + if ($passwordMatchStatus.length === 0) { + $passwordMatchStatus = $passwordConfirmMessage.find('span').first(); Drupal.deprecationError({ - message: 'Returning without data-drupal-selector="password-confirm-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101' + message: 'Returning without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101' }); } @@ -83,12 +83,12 @@ var confirmClass = passwordsAreMatching ? cssClasses.passwordsMatch : cssClasses.passwordsNotMatch; var confirmMessage = passwordsAreMatching ? settings.password.confirmSuccess : settings.password.confirmFailure; - if (!$confirmTextWrapper.hasClass(confirmClass) || !$confirmTextWrapper.html() === confirmMessage) { + if (!$passwordMatchStatus.hasClass(confirmClass) || !$passwordMatchStatus.html() === confirmMessage) { if (confirmTextWrapperClassesToRemove) { - $confirmTextWrapper.removeClass(confirmTextWrapperClassesToRemove); + $passwordMatchStatus.removeClass(confirmTextWrapperClassesToRemove); } - $confirmTextWrapper.html(confirmMessage).addClass(confirmClass); + $passwordMatchStatus.html(confirmMessage).addClass(confirmClass); } }; diff --git a/core/modules/user/user.theme.es6.js b/core/modules/user/user.theme.es6.js index b0034302c0..30db9e3b4c 100644 --- a/core/modules/user/user.theme.es6.js +++ b/core/modules/user/user.theme.es6.js @@ -18,7 +18,7 @@ */ Drupal.theme.passwordConfirmMessage = ({ confirmTitle }) => { const confirmTextWrapper = - ''; + ''; return `
${confirmTitle} ${confirmTextWrapper}
`; }; diff --git a/core/modules/user/user.theme.js b/core/modules/user/user.theme.js index 7848a65d35..2a3ae1eeaf 100644 --- a/core/modules/user/user.theme.js +++ b/core/modules/user/user.theme.js @@ -8,7 +8,7 @@ (function (Drupal) { Drupal.theme.passwordConfirmMessage = function (_ref) { var confirmTitle = _ref.confirmTitle; - var confirmTextWrapper = ''; + var confirmTextWrapper = ''; return "
".concat(confirmTitle, " ").concat(confirmTextWrapper, "
"); }; diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index d1ad7a1d12..b04fa6d9d5 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -140,6 +140,7 @@ public static function isDeprecationSkipped($message) { */ public static function getSkippedDeprecations() { return [ + 'hello', // The following deprecation message is skipped for testing purposes. '\Drupal\Tests\SkippedDeprecationTest deprecation', // The following Symfony deprecations are introduced in the Symfony 4 diff --git a/core/themes/claro/js/user.theme.es6.js b/core/themes/claro/js/user.theme.es6.js index 285291f578..ff269eb183 100644 --- a/core/themes/claro/js/user.theme.es6.js +++ b/core/themes/claro/js/user.theme.es6.js @@ -27,7 +27,7 @@ */ Drupal.theme.passwordConfirmMessage = ({ confirmTitle }) => { const confirmTextWrapper = - ''; + ''; return `
${confirmTitle} ${confirmTextWrapper}
`; }; diff --git a/core/themes/claro/js/user.theme.js b/core/themes/claro/js/user.theme.js index 773e22f53f..f2e3b141d9 100644 --- a/core/themes/claro/js/user.theme.js +++ b/core/themes/claro/js/user.theme.js @@ -17,7 +17,7 @@ Drupal.theme.passwordConfirmMessage = function (_ref) { var confirmTitle = _ref.confirmTitle; - var confirmTextWrapper = ''; + var confirmTextWrapper = ''; return "
".concat(confirmTitle, " ").concat(confirmTextWrapper, "
"); }; diff --git a/core/themes/stable/js/user.theme.es6.js b/core/themes/stable/js/user.theme.es6.js index 00888ca1fd..9c4f22d6cb 100644 --- a/core/themes/stable/js/user.theme.es6.js +++ b/core/themes/stable/js/user.theme.es6.js @@ -11,7 +11,7 @@ * A string representing a DOM fragment. */ Drupal.theme.passwordConfirmMessage = translate => - `
${translate.confirmTitle}
`; + `
${translate.confirmTitle}
`; /** * Constructs a password strength message. diff --git a/core/themes/stable/js/user.theme.js b/core/themes/stable/js/user.theme.js index 73d2fd0a46..2c76f6f1d2 100644 --- a/core/themes/stable/js/user.theme.js +++ b/core/themes/stable/js/user.theme.js @@ -7,7 +7,7 @@ (function (Drupal) { Drupal.theme.passwordConfirmMessage = function (translate) { - return "
".concat(translate.confirmTitle, "
"); + return "
".concat(translate.confirmTitle, "
"); }; Drupal.theme.passwordStrength = function (_ref) { diff --git a/core/themes/stable9/js/user.theme.es6.js b/core/themes/stable9/js/user.theme.es6.js index 8db998752c..ba20b55a8d 100644 --- a/core/themes/stable9/js/user.theme.es6.js +++ b/core/themes/stable9/js/user.theme.es6.js @@ -18,7 +18,7 @@ */ Drupal.theme.passwordConfirmMessage = ({ confirmTitle }) => { const confirmTextWrapper = - ''; + ''; return `
${confirmTitle} ${confirmTextWrapper}
`; }; diff --git a/core/themes/stable9/js/user.theme.js b/core/themes/stable9/js/user.theme.js index 7ba9435d77..4324b8cc3c 100644 --- a/core/themes/stable9/js/user.theme.js +++ b/core/themes/stable9/js/user.theme.js @@ -8,7 +8,7 @@ (function (Drupal) { Drupal.theme.passwordConfirmMessage = function (_ref) { var confirmTitle = _ref.confirmTitle; - var confirmTextWrapper = ''; + var confirmTextWrapper = ''; return "
".concat(confirmTitle, " ").concat(confirmTextWrapper, "
"); };