- Timestamp:
- 08/18/2024 11:43:37 PM (8 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.