diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 752b92dcde..6b7a974dbb 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3140,6 +3140,15 @@ function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { return; } + // Localize message content for user; fallback to site default for visitors. + if ( ! empty( $request->user_id ) ) { + $locale = get_user_locale( $request->user_id ); + } else { + $locale = get_locale(); + } + + $switched_locale = switch_to_locale( $locale ); + /** * Filters the recipient of the data erasure fulfillment notification. * @@ -3250,6 +3259,10 @@ All at ###SITENAME### $email_sent = wp_mail( $user_email, $subject, $content ); + if ( $switched_locale ) { + restore_previous_locale(); + } + if ( $email_sent ) { update_post_meta( $request_id, '_wp_user_notified', true ); } diff --git a/tests/phpunit/data/languages/de_DE.mo b/tests/phpunit/data/languages/de_DE.mo index b65a14e19c..3698ce3fda 100644 Binary files a/tests/phpunit/data/languages/de_DE.mo and b/tests/phpunit/data/languages/de_DE.mo differ diff --git a/tests/phpunit/data/languages/de_DE.po b/tests/phpunit/data/languages/de_DE.po index 4d66b76c10..c3ff771d5e 100644 --- a/tests/phpunit/data/languages/de_DE.po +++ b/tests/phpunit/data/languages/de_DE.po @@ -2,13 +2,13 @@ # This file is distributed under the same license as the 4.9.x package. msgid "" msgstr "" -"PO-Revision-Date: 2018-08-13 19:19+0300\n" +"PO-Revision-Date: 2019-03-27 22:27+0300\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Poedit 2.1.1\n" -"Project-Id-Version: Development (4.9.x)\n" +"X-Generator: Poedit 2.2.1\n" +"Project-Id-Version: Development (5.2.x)\n" "Language: de_DE\n" "POT-Creation-Date: \n" "Last-Translator: \n" @@ -48,3 +48,8 @@ msgstr "Jetzt %s aktualisieren" #: wp-includes/user.php:3445 msgid "[%1$s] Confirm Action: %2$s" msgstr "[%1$s] Aktion bestätigen: %2$s" + +#. translators: %s: Site name. +#: wp-includes/user.php:3175 +msgid "[%s] Erasure Request Fulfilled" +msgstr "[%s] Löschauftrag ausgeführt" diff --git a/tests/phpunit/data/languages/es_ES.mo b/tests/phpunit/data/languages/es_ES.mo index d4c5767eaf..3fe721e001 100644 Binary files a/tests/phpunit/data/languages/es_ES.mo and b/tests/phpunit/data/languages/es_ES.mo differ diff --git a/tests/phpunit/data/languages/es_ES.po b/tests/phpunit/data/languages/es_ES.po index 6e03a32de2..40eb0a5e11 100644 --- a/tests/phpunit/data/languages/es_ES.po +++ b/tests/phpunit/data/languages/es_ES.po @@ -2,13 +2,13 @@ # This file is distributed under the same license as the Development (4.9.x) package. msgid "" msgstr "" -"PO-Revision-Date: 2018-08-13 19:19+0300\n" +"PO-Revision-Date: 2019-03-27 22:27+0300\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Poedit 2.1.1\n" -"Project-Id-Version: Development (4.9.x)\n" +"X-Generator: Poedit 2.2.1\n" +"Project-Id-Version: Development (5.2.x)\n" "Language: es_ES\n" "POT-Creation-Date: \n" "Last-Translator: \n" @@ -44,3 +44,8 @@ msgstr "(Actualmente fijado en: %s)" #: wp-includes/user.php:3445 msgid "[%1$s] Confirm Action: %2$s" msgstr "[%1$s] Confirma la acción: %2$s" + +#. translators: %s: Site name. +#: wp-includes/user.php:3175 +msgid "[%s] Erasure Request Fulfilled" +msgstr "[%s] Solicitud de borrado completada" diff --git a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php index 3954970994..01c90ae3bc 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php @@ -34,6 +34,24 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT */ protected static $requester_email; + /** + * Request user. + * + * @since 5.2.0 + * + * @var WP_User $request_user + */ + protected static $request_user; + + /** + * Test administrator user. + * + * @since 5.2.0 + * + * @var WP_User $admin_user + */ + protected static $admin_user; + /** * Create user request fixtures shared by test methods. * @@ -43,7 +61,20 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT */ public static function wpSetUpBeforeClass( $factory ) { self::$requester_email = 'erase-my-data@local.test'; - self::$request_id = wp_create_user_request( self::$requester_email, 'erase_personal_data' ); + self::$request_user = $factory->user->create_and_get( + array( + 'user_email' => self::$requester_email, + 'role' => 'subscriber', + ) + ); + self::$admin_user = $factory->user->create_and_get( + array( + 'user_email' => 'admin@local.dev', + 'role' => 'administrator', + ) + ); + + self::$request_id = wp_create_user_request( self::$requester_email, 'remove_personal_data' ); wp_update_post( array( 'ID' => self::$request_id, @@ -69,6 +100,7 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT */ public function tearDown() { reset_phpmailer_instance(); + restore_previous_locale(); parent::tearDown(); } @@ -276,4 +308,139 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT $this->assertFalse( metadata_exists( 'post', self::$request_id, '_wp_user_notified' ) ); } + /** + * The function should respect the user locale settings when the site uses the default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale() { + update_user_meta( self::$request_user->ID, 'locale', 'es_ES' ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site does not use en_US, the administrator + * uses the site's default locale, and the user has a different locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_site_is_not_en_us() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$request_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site is not en_US, the administrator + * has a different selected locale, and the user uses the site's default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_admin_and_site_have_different_locales() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site is not en_US and both the + * administrator and the user use different locales. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_both_have_different_locales_than_site() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'en_US' ); + update_user_meta( self::$request_user->ID, 'locale', 'de_DE' ); + + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the site's locale when the request is for an unregistered user and the + * administrator does not use the site's locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_site_locale() { + update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' ); + wp_set_current_user( self::$admin_user->ID ); + + $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' ); + wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-completed', + ) + ); + + _wp_privacy_send_erasure_fulfillment_notification( $request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the site's locale when it is not en_US, the request is for an + * unregistered user, and the administrator does not use the site's default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_site_locale_when_not_en_us_and_admin_has_different_locale() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' ); + wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-completed', + ) + ); + + _wp_privacy_send_erasure_fulfillment_notification( $request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } }