Make WordPress Core


Ignore:
Timestamp:
08/18/2024 11:43:37 PM (7 weeks ago)
Author:
SergeyBiryukov
Message:

Tests: Bring some consistency to personal data email notification tests.

Includes:

  • Adding a test for wp_privacy_send_personal_data_export_email() to verify the user_request post type.
  • Reordering some pre-existing tests to check the request ID and post type first.

Follow-up to [43291], [43499], [44535].

Props garrett-eclipse, berubenic.
See #46560.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php

    r55337 r58912  
    100100
    101101    /**
     102     * The function should not send an email when the request ID does not exist.
     103     *
     104     * @ticket 44234
     105     */
     106    public function test_should_not_send_email_when_not_a_valid_request_id() {
     107        _wp_privacy_send_erasure_fulfillment_notification( 1234567890 );
     108
     109        $mailer = tests_retrieve_phpmailer_instance();
     110
     111        $this->assertEmpty( $mailer->mock_sent );
     112    }
     113
     114    /**
     115     * The function should not send an email when the ID passed does not correspond to a user request.
     116     *
     117     * @ticket 44234
     118     */
     119    public function test_should_not_send_email_when_not_a_user_request() {
     120        $post_id = self::factory()->post->create(
     121            array(
     122                'post_type' => 'post', // Should be 'user_request'.
     123            )
     124        );
     125
     126        _wp_privacy_send_erasure_fulfillment_notification( $post_id );
     127        $mailer = tests_retrieve_phpmailer_instance();
     128
     129        $this->assertEmpty( $mailer->mock_sent );
     130    }
     131
     132    /**
     133     * The function should not send an email when the request is not completed.
     134     *
     135     * @ticket 44234
     136     */
     137    public function test_should_not_send_email_when_request_not_completed() {
     138        wp_update_post(
     139            array(
     140                'ID'          => self::$request_id,
     141                'post_status' => 'request-confirmed', // Should be 'request-completed'.
     142            )
     143        );
     144
     145        _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     146
     147        $mailer = tests_retrieve_phpmailer_instance();
     148
     149        $this->assertEmpty( $mailer->mock_sent );
     150        $this->assertFalse( metadata_exists( 'post', self::$request_id, '_wp_user_notified' ) );
     151    }
     152
     153    /**
    102154     * The function should send an email when a valid request ID is passed.
    103155     *
     
    284336
    285337    /**
    286      * The function should not send an email when the request ID does not exist.
    287      *
    288      * @ticket 44234
    289      */
    290     public function test_should_not_send_email_when_passed_invalid_request_id() {
    291         _wp_privacy_send_erasure_fulfillment_notification( 1234567890 );
    292 
    293         $mailer = tests_retrieve_phpmailer_instance();
    294 
    295         $this->assertEmpty( $mailer->mock_sent );
    296     }
    297 
    298     /**
    299      * The function should not send an email when the ID passed does not correspond to a user request.
    300      *
    301      * @ticket 44234
    302      */
    303     public function test_should_not_send_email_when_not_user_request() {
    304         $post_id = self::factory()->post->create(
    305             array(
    306                 'post_type' => 'post', // Should be 'user_request'.
    307             )
    308         );
    309 
    310         _wp_privacy_send_erasure_fulfillment_notification( $post_id );
    311         $mailer = tests_retrieve_phpmailer_instance();
    312 
    313         $this->assertEmpty( $mailer->mock_sent );
    314     }
    315 
    316     /**
    317      * The function should not send an email when the request is not completed.
    318      *
    319      * @ticket 44234
    320      */
    321     public function test_should_not_send_email_when_request_not_completed() {
    322         wp_update_post(
    323             array(
    324                 'ID'          => self::$request_id,
    325                 'post_status' => 'request-confirmed', // Should be 'request-completed'.
    326             )
    327         );
    328 
    329         _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
    330 
    331         $mailer = tests_retrieve_phpmailer_instance();
    332 
    333         $this->assertEmpty( $mailer->mock_sent );
    334         $this->assertFalse( metadata_exists( 'post', self::$request_id, '_wp_user_notified' ) );
    335     }
    336 
    337     /**
    338338     * The function should respect the user locale settings when the site uses the default locale.
    339339     *
Note: See TracChangeset for help on using the changeset viewer.