/** * Set up a user and try sending a notification using `wp_new_user_notification( $user );`. * * @ticket 34377 */ function test_wp_new_user_notification_old_signature_no_password() { reset_phpmailer_instance(); $was_admin_email_sent = false; $was_user_email_sent = false; wp_new_user_notification(self::$contrib_id); /* * Check to see if a notification email was sent to the * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`. */ if (!empty($GLOBALS['phpmailer']->mock_sent)) { $was_admin_email_sent = isset($GLOBALS['phpmailer']->mock_sent[0]) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]; $was_user_email_sent = isset($GLOBALS['phpmailer']->mock_sent[1]) && '*****@*****.**' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0]; } $this->assertTrue($was_admin_email_sent); $this->assertFalse($was_user_email_sent); }
/** * Helper function to test sending author notifications. * * @since 4.4.0 * @access public */ public function try_sending_author_notification($comment, $post) { // Approve comments, triggering notifications. add_filter('pre_comment_approved', '__return_true'); // Post authors possibly notified when a comment is approved on their post. wp_set_comment_status($comment, 'approve'); // Check to see if a notification email was sent to the post author `test@test.com`. if (isset($GLOBALS['phpmailer']->mock_sent) && !empty($GLOBALS['phpmailer']->mock_sent) && '*****@*****.**' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]) { $email_sent_when_comment_approved = true; } else { $email_sent_when_comment_approved = false; } reset_phpmailer_instance(); // Post authors are notified when a new comment is added to their post. $data = array('comment_post_ID' => $post, 'comment_author' => rand_str(), 'comment_author_url' => '', 'comment_author_email' => '', 'comment_type' => '', 'comment_content' => rand_str()); wp_new_comment($data); // Check to see if a notification email was sent to the post author `test@test.com`. if (isset($GLOBALS['phpmailer']->mock_sent) && !empty($GLOBALS['phpmailer']->mock_sent) && '*****@*****.**' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]) { $email_sent_when_comment_added = true; reset_phpmailer_instance(); } else { $email_sent_when_comment_added = false; } return $email_sent_when_comment_approved || $email_sent_when_comment_added; }
function tearDown() { reset_phpmailer_instance(); parent::tearDown(); }