/** * Helper method to reset the phpmailer instance. * * @since 4.6.0 * * @return bool */ function reset_phpmailer_instance() { $mailer = tests_retrieve_phpmailer_instance(); if ($mailer && isset($mailer->mock_sent)) { unset($mailer->mock_sent); return true; } return false; }
/** * Testing wp_new_user_notification email statuses. * * @dataProvider data_wp_new_user_notifications * @ticket 33654 * @ticket 36009 */ function test_wp_new_user_notification($notify, $admin_email_sent_expected, $user_email_sent_expected) { reset_phpmailer_instance(); $was_admin_email_sent = false; $was_user_email_sent = false; wp_new_user_notification(self::$contrib_id, null, $notify); $mailer = tests_retrieve_phpmailer_instance(); /* * Check to see if a notification email was sent to the * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`. */ $first_recipient = $mailer->get_recipient('to'); if ($first_recipient) { $was_admin_email_sent = WP_TESTS_EMAIL === $first_recipient->address; $was_user_email_sent = '*****@*****.**' === $first_recipient->address; } $second_recipient = $mailer->get_recipient('to', 1); if ($second_recipient) { $was_user_email_sent = '*****@*****.**' === $second_recipient->address; } $this->assertSame($admin_email_sent_expected, $was_admin_email_sent, 'Admin email result was not as expected in test_wp_new_user_notification'); $this->assertSame($user_email_sent_expected, $was_user_email_sent, 'User email result was not as expected in test_wp_new_user_notification'); }
/** * @ticket 21659 */ public function test_wp_mail_addresses_arent_encoded() { $to = 'Lukáš To <*****@*****.**>'; $subject = 'Testing #21659'; $message = 'Only the name should be encoded, not the address.'; $headers = array('From' => 'From: Lukáš From <*****@*****.**>', 'Cc' => 'Cc: Lukáš CC <*****@*****.**>', 'Bcc' => 'Bcc: Lukáš BCC <*****@*****.**>', 'Reply-To' => 'Reply-To: Lukáš Reply-To <*****@*****.**>'); $expected = array('To' => 'To: =?UTF-8?B?THVrw6HFoSBUbw==?= <*****@*****.**>', 'From' => 'From: =?UTF-8?Q?Luk=C3=A1=C5=A1_From?= <*****@*****.**>', 'Cc' => 'Cc: =?UTF-8?B?THVrw6HFoSBDQw==?= <*****@*****.**>', 'Bcc' => 'Bcc: =?UTF-8?B?THVrw6HFoSBCQ0M=?= <*****@*****.**>', 'Reply-To' => 'Reply-To: =?UTF-8?Q?Luk=C3=A1=C5=A1_Reply-To?= <*****@*****.**>'); wp_mail($to, $subject, $message, array_values($headers)); $mailer = tests_retrieve_phpmailer_instance(); $sent_headers = preg_split("/\r\n|\n|\r/", $mailer->get_sent()->header); $headers['To'] = "To: {$to}"; foreach ($headers as $header => $value) { $target_headers = preg_grep("/^{$header}:/", $sent_headers); $this->assertEquals($expected[$header], array_pop($target_headers)); } }
/** * Test that the Sender field in the SMTP envelope is not set by Core. * * Correctly setting the Sender requires knowledge that is not available * to Core. An incorrect value will often lead to messages being rejected * by the receiving MTA, so it's the admin's responsibility to * set it correctly. * * @ticket 37736 */ public function test_wp_mail_sender_not_set() { wp_mail('*****@*****.**', 'Testing the Sender field', 'The Sender field should not have been set.'); $mailer = tests_retrieve_phpmailer_instance(); $this->assertEquals('', $mailer->Sender); }
/** * @ticket 30266 */ public function test_wp_mail_with_empty_charset_for_the_content_type_header() { $to = '*****@*****.**'; $subject = 'Testing'; $message = 'Test Message'; $headers = 'Content-Type: text/plain;'; $expected = 'Content-Type: text/plain; charset=UTF-8'; wp_mail($to, $subject, $message, $headers); $mailer = tests_retrieve_phpmailer_instance(); $this->assertTrue(strpos($mailer->get_sent()->header, $expected) > 0); }