WordPress.org

Make WordPress Core

Ticket #44721: 44721.4.diff

File 44721.4.diff, 9.5 KB (added by garrett-eclipse, 9 months ago)

Updated unit tests to address issues and a failing test.

  • src/wp-includes/user.php

     
    31433143                return;
    31443144        }
    31453145
     3146        // Localize message content for user; fallback to site default for visitors.
     3147        if ( ! empty( $request->user_id ) ) {
     3148                $locale = get_user_locale( $request->user_id );
     3149        } else {
     3150                $locale = get_locale();
     3151        }
     3152
     3153        $switched_locale = switch_to_locale( $locale );
     3154
    31463155        /**
    31473156         * Filters the recipient of the data erasure fulfillment notification.
    31483157         *
     
    32533262
    32543263        $email_sent = wp_mail( $user_email, $subject, $content );
    32553264
     3265        if ( $switched_locale ) {
     3266                restore_previous_locale();
     3267        }
     3268
    32563269        if ( $email_sent ) {
    32573270                update_post_meta( $request_id, '_wp_user_notified', true );
    32583271        }
  • 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: 2018-05-15 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"
    1010"X-Generator: Poedit 2.1.1\n"
    11 "Project-Id-Version: Development (4.9.x)\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#. translators: %s: Site name.
     53#: wp-includes/user.php:3175
     54msgid "[%s] Erasure Request Fulfilled"
     55msgstr "[%s] Löschauftrag ausgeführt"
  • 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-03-16 02:41-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\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#. translators: %s: Site name.
     49#: wp-includes/user.php:3175
     50msgid "[%s] Erasure Request Fulfilled"
     51msgstr "[%s] Solicitud de borrado completada"
  • tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.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         * Create user request fixtures shared by test methods.
    3957         *
    4058         * @since 5.1.0
     
    4361         */
    4462        public static function wpSetUpBeforeClass( $factory ) {
    4563                self::$requester_email = 'erase-my-data@local.test';
    46                 self::$request_id      = wp_create_user_request( self::$requester_email, 'erase_personal_data' );
     64                self::$request_user    = $factory->user->create_and_get(
     65                        array(
     66                                'user_email' => self::$requester_email,
     67                                'role'       => 'subscriber',
     68                        )
     69                );
     70                self::$admin_user      = $factory->user->create_and_get(
     71                        array(
     72                                'user_email' => 'admin@local.dev',
     73                                'role'       => 'administrator',
     74                        )
     75                );
     76
     77                self::$request_id = wp_create_user_request( self::$requester_email, 'remove_personal_data' );
    4778                wp_update_post(
    4879                        array(
    4980                                'ID'          => self::$request_id,
     
    69100         */
    70101        public function tearDown() {
    71102                reset_phpmailer_instance();
     103                restore_previous_locale();
    72104                parent::tearDown();
    73105        }
    74106
     
    276308                $this->assertFalse( metadata_exists( 'post', self::$request_id, '_wp_user_notified' ) );
    277309        }
    278310
     311        /**
     312         * The function should respect the user locale settings when the site uses the default locale.
     313         *
     314         * @ticket 44721
     315         * @group l10n
     316         */
     317        public function test_should_send_fulfillment_email_in_user_locale() {
     318                update_user_meta( self::$request_user->ID, 'locale', 'es_ES' );
     319
     320                _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     321                $mailer = tests_retrieve_phpmailer_instance();
     322
     323                $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     324        }
     325
     326        /**
     327         * The function should respect the user locale settings when the site does not use en_US, the administrator
     328         * uses the site's default locale, and the user has a different locale.
     329         *
     330         * @ticket 44721
     331         * @group l10n
     332         */
     333        public function test_should_send_fulfillment_email_in_user_locale_when_site_is_not_en_us() {
     334                update_option( 'WPLANG', 'es_ES' );
     335                switch_to_locale( 'es_ES' );
     336
     337                update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     338                wp_set_current_user( self::$admin_user->ID );
     339
     340                _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     341                $mailer = tests_retrieve_phpmailer_instance();
     342
     343                $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     344        }
     345
     346        /**
     347         * The function should respect the user locale settings when the site is not en_US, the administrator
     348         * has a different selected locale, and the user uses the site's default locale.
     349         *
     350         * @ticket 44721
     351         * @group l10n
     352         */
     353        public function test_should_send_fulfillment_email_in_user_locale_when_admin_and_site_have_different_locales() {
     354                update_option( 'WPLANG', 'es_ES' );
     355                switch_to_locale( 'es_ES' );
     356
     357                update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     358                wp_set_current_user( self::$admin_user->ID );
     359
     360                _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     361                $mailer = tests_retrieve_phpmailer_instance();
     362
     363                $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     364        }
     365
     366        /**
     367         * The function should respect the user locale settings when the site is not en_US and both the
     368         * administrator and the user use different locales.
     369         *
     370         * @ticket 44721
     371         * @group l10n
     372         */
     373        public function test_should_send_fulfillment_email_in_user_locale_when_both_have_different_locales_than_site() {
     374                update_option( 'WPLANG', 'es_ES' );
     375                switch_to_locale( 'es_ES' );
     376
     377                update_user_meta( self::$admin_user->ID, 'locale', 'en_US' );
     378                update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     379
     380                wp_set_current_user( self::$admin_user->ID );
     381
     382                _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     383                $mailer = tests_retrieve_phpmailer_instance();
     384
     385                $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     386        }
     387
     388        /**
     389         * The function should respect the site's locale when the request is for an unregistered user and the
     390         * administrator does not use the site's locale.
     391         *
     392         * @ticket 44721
     393         * @group l10n
     394         */
     395        public function test_should_send_fulfillment_email_in_site_locale() {
     396                update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' );
     397                wp_set_current_user( self::$admin_user->ID );
     398
     399                $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' );
     400                wp_update_post(
     401                        array(
     402                                'ID'          => $request_id,
     403                                'post_status' => 'request-completed',
     404                        )
     405                );
     406
     407                _wp_privacy_send_erasure_fulfillment_notification( $request_id );
     408                $mailer = tests_retrieve_phpmailer_instance();
     409
     410                $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
     411        }
     412
     413        /**
     414         * The function should respect the site's locale when it is not en_US, the request is for an
     415         * unregistered user, and the administrator does not use the site's default locale.
     416         *
     417         * @ticket 44721
     418         * @group l10n
     419         */
     420        public function test_should_send_fulfillment_email_in_site_locale_when_not_en_us_and_admin_has_different_locale() {
     421                update_option( 'WPLANG', 'es_ES' );
     422                switch_to_locale( 'es_ES' );
     423
     424                update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     425                wp_set_current_user( self::$admin_user->ID );
     426
     427                $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' );
     428                wp_update_post(
     429                        array(
     430                                'ID'          => $request_id,
     431                                'post_status' => 'request-completed',
     432                        )
     433                );
     434
     435                _wp_privacy_send_erasure_fulfillment_notification( $request_id );
     436                $mailer = tests_retrieve_phpmailer_instance();
     437
     438                $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     439        }
    279440}