Changeset 58912
- Timestamp:
- 08/18/2024 11:43:37 PM (4 weeks ago)
- Location:
- trunk/tests/phpunit/tests/privacy
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php
r55337 r58912 100 100 101 101 /** 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 /** 102 154 * The function should send an email when a valid request ID is passed. 103 155 * … … 284 336 285 337 /** 286 * The function should not send an email when the request ID does not exist.287 *288 * @ticket 44234289 */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 44234302 */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 44234320 */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 /**338 338 * The function should respect the user locale settings when the site uses the default locale. 339 339 * -
trunk/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php
r55337 r58912 46 46 */ 47 47 protected static $admin_user; 48 49 /**50 * Reset the mocked phpmailer instance before each test method.51 *52 * @since 4.9.653 */54 public function set_up() {55 parent::set_up();56 reset_phpmailer_instance();57 }58 59 /**60 * Reset the mocked phpmailer instance after each test method.61 *62 * @since 4.9.663 */64 public function tear_down() {65 reset_phpmailer_instance();66 restore_previous_locale();67 parent::tear_down();68 }69 48 70 49 /** … … 96 75 97 76 /** 77 * Reset the mocked phpmailer instance before each test method. 78 * 79 * @since 4.9.6 80 */ 81 public function set_up() { 82 parent::set_up(); 83 reset_phpmailer_instance(); 84 } 85 86 /** 87 * Reset the mocked phpmailer instance after each test method. 88 * 89 * @since 4.9.6 90 */ 91 public function tear_down() { 92 reset_phpmailer_instance(); 93 restore_previous_locale(); 94 parent::tear_down(); 95 } 96 97 /** 98 * The function should error when the request ID does not exist. 99 * 100 * @since 4.9.6 101 */ 102 public function test_should_return_wp_error_when_not_a_valid_request_id() { 103 $request_id = 0; 104 $email_sent = wp_privacy_send_personal_data_export_email( $request_id ); 105 $this->assertWPError( $email_sent ); 106 $this->assertSame( 'invalid_request', $email_sent->get_error_code() ); 107 108 $request_id = PHP_INT_MAX; 109 $email_sent = wp_privacy_send_personal_data_export_email( $request_id ); 110 $this->assertWPError( $email_sent ); 111 $this->assertSame( 'invalid_request', $email_sent->get_error_code() ); 112 } 113 114 /** 115 * The function should error when the ID passed does not correspond to a user request. 116 * 117 * @since 6.7.0 118 * @ticket 46560 119 */ 120 public function test_should_return_wp_error_when_not_a_user_request() { 121 $post_id = self::factory()->post->create( 122 array( 123 'post_type' => 'post', // Should be 'user_request'. 124 ) 125 ); 126 127 $email_sent = wp_privacy_send_personal_data_export_email( $post_id ); 128 $this->assertWPError( $email_sent ); 129 $this->assertSame( 'invalid_request', $email_sent->get_error_code() ); 130 } 131 132 /** 133 * The function should error when the email was not sent. 134 * 135 * @since 4.9.6 136 */ 137 public function test_should_return_wp_error_when_sending_fails() { 138 add_filter( 'wp_mail_from', '__return_empty_string' ); // Cause `wp_mail()` to return false. 139 $email_sent = wp_privacy_send_personal_data_export_email( self::$request_id ); 140 141 $this->assertWPError( $email_sent ); 142 $this->assertSame( 'privacy_email_error', $email_sent->get_error_code() ); 143 } 144 145 /** 98 146 * The function should send an export link to the requester when the user request is confirmed. 99 147 */ 100 public function test_ function_should_send_export_link_to_requester() {148 public function test_should_send_export_link_to_requester() { 101 149 $exports_url = wp_privacy_exports_url(); 102 150 $export_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip'; … … 113 161 $this->assertStringContainsString( 'please download it', $mailer->get_sent()->body ); 114 162 $this->assertTrue( $email_sent ); 115 }116 117 /**118 * The function should error when the request ID is invalid.119 *120 * @since 4.9.6121 */122 public function test_function_should_error_when_request_id_invalid() {123 $request_id = 0;124 $email_sent = wp_privacy_send_personal_data_export_email( $request_id );125 $this->assertWPError( $email_sent );126 $this->assertSame( 'invalid_request', $email_sent->get_error_code() );127 128 $request_id = PHP_INT_MAX;129 $email_sent = wp_privacy_send_personal_data_export_email( $request_id );130 $this->assertWPError( $email_sent );131 $this->assertSame( 'invalid_request', $email_sent->get_error_code() );132 }133 134 /**135 * The function should error when the email was not sent.136 *137 * @since 4.9.6138 */139 public function test_return_wp_error_when_send_fails() {140 add_filter( 'wp_mail_from', '__return_empty_string' ); // Cause `wp_mail()` to return false.141 $email_sent = wp_privacy_send_personal_data_export_email( self::$request_id );142 143 $this->assertWPError( $email_sent );144 $this->assertSame( 'privacy_email_error', $email_sent->get_error_code() );145 163 } 146 164 -
trunk/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php
r56547 r58912 33 33 34 34 /** 35 * The function should not send emailswhen the request ID does not exist.36 * 37 * @ticket 43967 38 */ 39 public function test_ function_should_not_send_email_when_not_a_valid_request_id() {35 * The function should not send an email when the request ID does not exist. 36 * 37 * @ticket 43967 38 */ 39 public function test_should_not_send_email_when_not_a_valid_request_id() { 40 40 _wp_privacy_send_request_confirmation_notification( 1234567890 ); 41 41 $mailer = tests_retrieve_phpmailer_instance(); … … 45 45 46 46 /** 47 * The function should not send emails when the ID passed is not a WP_User_Request.48 * 49 * @ticket 43967 50 */ 51 public function test_ function_should_not_send_email_when_not_a_wp_user_request() {47 * The function should not send an email when the ID passed does not correspond to a user request. 48 * 49 * @ticket 43967 50 */ 51 public function test_should_not_send_email_when_not_a_user_request() { 52 52 $post_id = self::factory()->post->create( 53 53 array( 54 'post_type' => 'post', 54 'post_type' => 'post', // Should be 'user_request'. 55 55 ) 56 56 ); … … 67 67 * @ticket 43967 68 68 */ 69 public function test_ function_should_send_email_to_site_admin_when_user_request_confirmed() {69 public function test_should_send_email_to_site_admin_when_user_request_confirmed() { 70 70 $email = 'export.request.from.unregistered.user@example.com'; 71 71 $request_id = wp_create_user_request( $email, 'export_personal_data' ); … … 90 90 * @ticket 43967 91 91 */ 92 public function test_ function_should_only_send_email_to_site_admin_when_user_request_is_confirmed() {92 public function test_should_only_send_email_to_site_admin_when_user_request_is_confirmed() { 93 93 $email = 'export.request.from.unregistered.user@example.com'; 94 94 $request_id = wp_create_user_request( $email, 'export_personal_data' ); … … 110 110 * @ticket 43967 111 111 */ 112 public function test_ function_should_only_send_email_once_to_admin_when_user_request_is_confirmed() {112 public function test_should_only_send_email_once_to_admin_when_user_request_is_confirmed() { 113 113 $email = 'export.request.from.unregistered.user@example.com'; 114 114 $request_id = wp_create_user_request( $email, 'export_personal_data' );
Note: See TracChangeset
for help on using the changeset viewer.