diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 11e5f9231f..bbae7bed4d 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -2353,6 +2353,15 @@ function wp_privacy_send_personal_data_export_email( $request_id ) { return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) ); } + // 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 ); + /** This filter is documented in wp-includes/functions.php */ $expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS ); $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration ); @@ -2409,6 +2418,10 @@ All at ###SITENAME### $content ); + if ( $switched_locale ) { + restore_previous_locale(); + } + if ( ! $mail_success ) { return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) ); } diff --git a/tests/phpunit/data/languages/de_DE.mo b/tests/phpunit/data/languages/de_DE.mo index 3698ce3fda..dcfef58f48 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 c3ff771d5e..aa97af62e9 100644 --- a/tests/phpunit/data/languages/de_DE.po +++ b/tests/phpunit/data/languages/de_DE.po @@ -1,8 +1,8 @@ -# Translation of 4.9.x in German -# This file is distributed under the same license as the 4.9.x package. +# Translation of 5.2.x in German +# This file is distributed under the same license as the 5.2.x package. msgid "" msgstr "" -"PO-Revision-Date: 2019-03-27 22:27+0300\n" +"PO-Revision-Date: 2019-03-28 19:42+0300\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -53,3 +53,7 @@ msgstr "[%1$s] Aktion bestätigen: %2$s" #: wp-includes/user.php:3175 msgid "[%s] Erasure Request Fulfilled" msgstr "[%s] Löschauftrag ausgeführt" + +#: wp-admin/includes/file.php:2415 +msgid "[%s] Personal Data Export" +msgstr "[%s] Export personenbezogener Daten" diff --git a/tests/phpunit/data/languages/es_ES.mo b/tests/phpunit/data/languages/es_ES.mo index 3fe721e001..bd56b36d4c 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 40eb0a5e11..511874825e 100644 --- a/tests/phpunit/data/languages/es_ES.po +++ b/tests/phpunit/data/languages/es_ES.po @@ -1,8 +1,8 @@ -# Translation of Development (4.9.x) in Spanish (Spain) -# This file is distributed under the same license as the Development (4.9.x) package. +# Translation of Development (5.2.x) in Spanish (Spain) +# This file is distributed under the same license as the Development (5.2.x) package. msgid "" msgstr "" -"PO-Revision-Date: 2019-03-27 22:27+0300\n" +"PO-Revision-Date: 2019-03-28 19:43+0300\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -49,3 +49,7 @@ msgstr "[%1$s] Confirma la acción: %2$s" #: wp-includes/user.php:3175 msgid "[%s] Erasure Request Fulfilled" msgstr "[%s] Solicitud de borrado completada" + +#: wp-admin/includes/file.php:2415 +msgid "[%s] Personal Data Export" +msgstr "[%s] Exportación de datos personales" diff --git a/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php b/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php index 523ec76981..a270d70b61 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php @@ -34,6 +34,24 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase */ 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; + /** * Reset the mocked phpmailer instance before each test method. * @@ -51,6 +69,7 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase */ public function tearDown() { reset_phpmailer_instance(); + restore_previous_locale(); parent::tearDown(); } @@ -63,6 +82,19 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase */ public static function wpSetUpBeforeClass( $factory ) { self::$requester_email = 'requester@example.com'; + 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, 'export_personal_data' ); _wp_privacy_account_request_confirmed( self::$request_id ); @@ -167,4 +199,136 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase public function modify_email_content( $email_text, $request_id ) { return 'Custom content for request ID: ' . $request_id; } + + /** + * The function should respect the user locale settings when the site uses the default locale. + * + * @since 5.2.0 + * @ticket 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_email_in_user_locale() { + update_user_meta( self::$request_user->ID, 'locale', 'es_ES' ); + + wp_privacy_send_personal_data_export_email( self::$request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Exportación de datos personales', $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 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_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_personal_data_export_email( self::$request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Export personenbezogener Daten', $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 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_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_personal_data_export_email( self::$request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Exportación de datos personales', $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 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_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_personal_data_export_email( self::$request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Export personenbezogener Daten', $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 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_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( 'export-user-not-registered@example.com', 'export_personal_data' ); + + _wp_privacy_account_request_confirmed( self::$request_id ); + wp_privacy_send_personal_data_export_email( $request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Personal Data Export', $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 46056 + * @group l10n + */ + public function test_should_send_personal_data_export_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( 'export-user-not-registered@example.com', 'export_personal_data' ); + + _wp_privacy_account_request_confirmed( self::$request_id ); + wp_privacy_send_personal_data_export_email( $request_id ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject ); + } }