WordPress.org

Make WordPress Core

Ticket #46056: 46056.2.diff

File 46056.2.diff, 9.8 KB (added by garrett-eclipse, 19 months ago)

Added Unit Tests following the convention set in #44721

  • src/wp-admin/includes/file.php

     
    21872187                return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
    21882188        }
    21892189
     2190        // Localize message content for user; fallback to site default for visitors.
     2191        if ( ! empty( $request->user_id ) ) {
     2192                $locale = get_user_locale( $request->user_id );
     2193        } else {
     2194                $locale = get_locale();
     2195        }
     2196
     2197        $switched_locale = switch_to_locale( $locale );
     2198
    21902199        /** This filter is documented in wp-includes/functions.php */
    21912200        $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    21922201        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
     
    22432252                $content
    22442253        );
    22452254
     2255        if ( $switched_locale ) {
     2256                restore_previous_locale();
     2257        }
     2258
    22462259        if ( ! $mail_success ) {
    22472260                return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) );
    22482261        }
  • tests/phpunit/data/languages/de_DE.po

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    22# This file is distributed under the same license as the 4.9.x package.
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2018-08-13 19:19+0300\n"
     5"PO-Revision-Date: 2019-03-19 00:29-0700\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    99"Plural-Forms: nplurals=2; plural=n != 1;\n"
    10 "X-Generator: Poedit 2.1.1\n"
    11 "Project-Id-Version: Development (4.9.x)\n"
     10"X-Generator: Poedit 2.2.1\n"
     11"Project-Id-Version: Development (5.2.x)\n"
    1212"Language: de_DE\n"
    1313"POT-Creation-Date: \n"
    1414"Last-Translator: \n"
     
    4848#: wp-includes/user.php:3445
    4949msgid "[%1$s] Confirm Action: %2$s"
    5050msgstr "[%1$s] Aktion bestätigen: %2$s"
     51
     52#: wp-admin/includes/file.php:2249
     53msgid "[%s] Personal Data Export"
     54msgstr "[%s] Export personenbezogener Daten"
  • tests/phpunit/data/languages/es_ES.po

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    22# This file is distributed under the same license as the Development (4.9.x) package.
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2018-08-13 19:19+0300\n"
     5"PO-Revision-Date: 2019-04-19 19:19+0300\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    99"Plural-Forms: nplurals=2; plural=n != 1;\n"
    10 "X-Generator: Poedit 2.1.1\n"
    11 "Project-Id-Version: Development (4.9.x)\n"
     10"X-Generator: Poedit 2.2.1\n"
     11"Project-Id-Version: Development (5.2.x)\n"
    1212"Language: es_ES\n"
    1313"POT-Creation-Date: \n"
    1414"Last-Translator: \n"
     
    4444#: wp-includes/user.php:3445
    4545msgid "[%1$s] Confirm Action: %2$s"
    4646msgstr "[%1$s] Confirma la acción: %2$s"
     47
     48#: wp-admin/includes/file.php:2249
     49msgid "[%s] Personal Data Export"
     50msgstr "[%s] Exportación de datos personales"
     51 No newline at end of file
  • tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

     
    3535        protected static $requester_email;
    3636
    3737        /**
     38         * Request user.
     39         *
     40         * @since 5.2.0
     41         *
     42         * @var WP_User $request_user
     43         */
     44        protected static $request_user;
     45
     46        /**
     47         * Test administrator user.
     48         *
     49         * @since 5.2.0
     50         *
     51         * @var WP_User $admin_user
     52         */
     53        protected static $admin_user;
     54
     55        /**
    3856         * Reset the mocked phpmailer instance before each test method.
    3957         *
    4058         * @since 4.9.6
     
    5169         */
    5270        public function tearDown() {
    5371                reset_phpmailer_instance();
     72                restore_previous_locale();
    5473                parent::tearDown();
    5574        }
    5675
     
    6382         */
    6483        public static function wpSetUpBeforeClass( $factory ) {
    6584                self::$requester_email = 'requester@example.com';
     85                self::$request_user    = $factory->user->create_and_get(
     86                        array(
     87                                'user_email' => self::$requester_email,
     88                                'role'       => 'subscriber',
     89                        )
     90                );
     91                self::$admin_user      = $factory->user->create_and_get(
     92                        array(
     93                                'user_email' => 'admin@local.dev',
     94                                'role'       => 'administrator',
     95                        )
     96                );
     97
    6698                self::$request_id      = wp_create_user_request( self::$requester_email, 'export_personal_data' );
    6799
    68100                _wp_privacy_account_request_confirmed( self::$request_id );
     
    167199        public function modify_email_content( $email_text, $request_id ) {
    168200                return 'Custom content for request ID: ' . $request_id;
    169201        }
     202
     203        /**
     204         * The function should respect the user locale settings when the site uses the default locale.
     205         *
     206         * @since 5.2.0
     207         * @ticket 46056
     208         * @group l10n
     209         */
     210        public function test_should_send_personal_data_export_email_in_user_locale() {
     211                update_user_meta( self::$request_user->ID, 'locale', 'es_ES' );
     212
     213                wp_privacy_send_personal_data_export_email( self::$request_id );
     214               
     215                $mailer = tests_retrieve_phpmailer_instance();
     216
     217                $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     218        }
     219
     220        /**
     221         * The function should respect the user locale settings when the site does not use en_US, the administrator
     222         * uses the site's default locale, and the user has a different locale.
     223         *
     224         * @since 5.2.0
     225         * @ticket 46056
     226         * @group l10n
     227         */
     228        public function test_should_send_personal_data_export_email_in_user_locale_when_site_is_not_en_us() {
     229                update_option( 'WPLANG', 'es_ES' );
     230                switch_to_locale( 'es_ES' );
     231
     232                update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     233                wp_set_current_user( self::$admin_user->ID );
     234
     235                wp_privacy_send_personal_data_export_email( self::$request_id );
     236
     237                $mailer = tests_retrieve_phpmailer_instance();
     238
     239                $this->assertContains( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
     240        }
     241
     242        /**
     243         * The function should respect the user locale settings when the site is not en_US, the administrator
     244         * has a different selected locale, and the user uses the site's default locale.
     245         *
     246         * @since 5.2.0
     247         * @ticket 46056
     248         * @group l10n
     249         */
     250        public function test_should_send_personal_data_export_email_in_user_locale_when_admin_and_site_have_different_locales() {
     251                update_option( 'WPLANG', 'es_ES' );
     252                switch_to_locale( 'es_ES' );
     253
     254                update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     255                wp_set_current_user( self::$admin_user->ID );
     256
     257                wp_privacy_send_personal_data_export_email( self::$request_id );
     258
     259                $mailer = tests_retrieve_phpmailer_instance();
     260
     261                $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     262        }
     263
     264        /**
     265         * The function should respect the user locale settings when the site is not en_US and both the
     266         * administrator and the user use different locales.
     267         *
     268         * @since 5.2.0
     269         * @ticket 46056
     270         * @group l10n
     271         */
     272        public function test_should_send_personal_data_export_email_in_user_locale_when_both_have_different_locales_than_site() {
     273                update_option( 'WPLANG', 'es_ES' );
     274                switch_to_locale( 'es_ES' );
     275
     276                update_user_meta( self::$admin_user->ID, 'locale', 'en_US' );
     277                update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     278
     279                wp_set_current_user( self::$admin_user->ID );
     280
     281                wp_privacy_send_personal_data_export_email( self::$request_id );
     282
     283                $mailer = tests_retrieve_phpmailer_instance();
     284
     285                $this->assertContains( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
     286        }
     287
     288        /**
     289         * The function should respect the site's locale when the request is for an unregistered user and the
     290         * administrator does not use the site's locale.
     291         *
     292         * @since 5.2.0
     293         * @ticket 46056
     294         * @group l10n
     295         */
     296        public function test_should_send_personal_data_export_email_in_site_locale() {
     297                update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' );
     298                wp_set_current_user( self::$admin_user->ID );
     299
     300                $request_id = wp_create_user_request( 'export-user-not-registered@example.com', 'export_personal_data' );
     301
     302                _wp_privacy_account_request_confirmed( self::$request_id );
     303                wp_privacy_send_personal_data_export_email( $request_id );
     304
     305                $mailer = tests_retrieve_phpmailer_instance();
     306
     307                $this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject );
     308        }
     309
     310        /**
     311         * The function should respect the site's locale when it is not en_US, the request is for an
     312         * unregistered user, and the administrator does not use the site's default locale.
     313         *
     314         * @since 5.2.0
     315         * @ticket 46056
     316         * @group l10n
     317         */
     318        public function test_should_send_personal_data_export_email_in_site_locale_when_not_en_us_and_admin_has_different_locale() {
     319                update_option( 'WPLANG', 'es_ES' );
     320                switch_to_locale( 'es_ES' );
     321
     322                update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     323                wp_set_current_user( self::$admin_user->ID );
     324
     325                $request_id = wp_create_user_request( 'export-user-not-registered@example.com', 'export_personal_data' );
     326
     327                _wp_privacy_account_request_confirmed( self::$request_id );
     328                wp_privacy_send_personal_data_export_email( $request_id );
     329
     330                $mailer = tests_retrieve_phpmailer_instance();
     331
     332                $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     333        }
    170334}