Changeset 41255 for trunk/tests/phpunit/tests/user.php
- Timestamp:
- 08/15/2017 09:15:53 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user.php
r41171 r41255 1140 1140 1141 1141 /** 1142 * Ensure blog's admin email change notification emails do not contain encoded HTML entities 1143 * @ticket 40015 1144 */ 1145 function test_new_admin_email_notification_html_entities_decoded() { 1146 reset_phpmailer_instance(); 1147 1148 wp_set_current_user( self::$admin_id ); 1149 1150 $existing_email = get_option( 'admin_email' ); 1151 $new_email = 'new-admin-email@test.dev'; 1152 1153 // Give the site a name containing HTML entities 1154 update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); 1155 1156 update_option_new_admin_email( $existing_email, $new_email ); 1157 1158 $mailer = tests_retrieve_phpmailer_instance(); 1159 1160 $recipient = $mailer->get_recipient( 'to' ); 1161 $email = $mailer->get_sent(); 1162 1163 // Assert reciepient is correct 1164 $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' ); 1165 1166 // Assert that HTML entites have been decode in body and subject 1167 $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); 1168 $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' ); 1169 } 1170 1171 /** 1172 * A confirmation email should not be sent if the new admin email: 1173 * - Matches the existing admin email, or 1174 * - is not a valid email 1175 * 1176 * @dataProvider data_user_admin_email_confirmation_emails 1177 */ 1178 function test_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) { 1179 reset_phpmailer_instance(); 1180 1181 update_option_new_admin_email( get_option( 'admin_email' ), $email ); 1182 1183 $mailer = tests_retrieve_phpmailer_instance(); 1184 1185 $this->assertFalse( $mailer->get_sent(), $message ); 1186 } 1187 1188 /** 1189 * Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid(). 1190 * 1191 * @return array { 1192 * @type array { 1193 * @type string $email The new email for admin_email 1194 * @type string $message An error message to display if the test fails 1195 * } 1196 * } 1197 */ 1198 function data_user_admin_email_confirmation_emails() { 1199 return array( 1200 array( 1201 get_option( 'admin_email' ), 1202 'A confirmation email should not be sent if the current admin email matches the new email', 1203 ), 1204 array( 1205 'not an email', 1206 'A confirmation email should not be sent if it is not a valid email', 1207 ) 1208 ); 1209 } 1210 1211 /** 1212 * A confirmation email should not be sent if user's new email: 1213 * - Matches their existing email, or 1214 * - is not a valid email, or 1215 * - Matches another user's email 1216 * 1217 * @dataProvider data_user_change_email_confirmation_emails 1218 */ 1219 function test_profile_email_confirmation_not_sent_invalid_email( $email, $message ) { 1220 1221 $old_current = get_current_user_id(); 1222 1223 $user_id = self::factory()->user->create( array( 1224 'role' => 'subscriber', 1225 'user_email' => 'email@test.dev', 1226 ) ); 1227 wp_set_current_user( $user_id ); 1228 1229 self::factory()->user->create( array( 1230 'role' => 'subscriber', 1231 'user_email' => 'another-user@test.dev', 1232 ) ); 1233 1234 reset_phpmailer_instance(); 1235 1236 // Set $_POST['email'] with new email and $_POST['id'] with user's ID. 1237 $_POST['user_id'] = $user_id; 1238 $_POST['email'] = $email; 1239 send_confirmation_on_profile_email(); 1240 1241 $mailer = tests_retrieve_phpmailer_instance(); 1242 1243 $this->assertFalse( $mailer->get_sent(), $message ); 1244 1245 wp_set_current_user( $old_current ); 1246 } 1247 1248 /** 1249 * Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email(). 1250 * 1251 * @return array { 1252 * @type array { 1253 * @type string $email The user's new e-amil. 1254 * @type string $message An error message to display if the test fails 1255 * } 1256 * } 1257 */ 1258 function data_user_change_email_confirmation_emails() { 1259 return array( 1260 array( 1261 'email@test.dev', 1262 'Confirmation email should not be sent if it matches the user\'s existing email', 1263 ), 1264 array( 1265 'not an email', 1266 'Confirmation email should not be sent if it is not a valid email', 1267 ), 1268 array( 1269 'another-user@test.dev', 1270 'Confirmation email should not be sent if it matches another user\'s email', 1271 ), 1272 ); 1273 } 1274 1275 /** 1142 1276 * Checks that calling edit_user() with no password returns an error when adding, and doesn't when updating. 1143 1277 *
Note: See TracChangeset
for help on using the changeset viewer.