| 682 | /** |
| 683 | * Testing wp_new_user_notification email statuses. |
| 684 | * |
| 685 | * Be sure when writing tests to unset any old instances of |
| 686 | * $GLOBALS['phpmailer'] or depending on array indices will be |
| 687 | * inaccurate. |
| 688 | * |
| 689 | * @dataProvider data_wp_new_user_notifications |
| 690 | * |
| 691 | * @ticket 33654 |
| 692 | * |
| 693 | * |
| 694 | */ |
| 695 | function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) { |
| 696 | |
| 697 | //unset any old instance of phpmailer |
| 698 | unset( $GLOBALS['phpmailer']->mock_sent ); |
| 699 | |
| 700 | $was_admin_email_sent = false; |
| 701 | $was_user_email_sent = false; |
| 702 | |
| 703 | $user = $this->factory->user->create( $this->user_data ); |
| 704 | |
| 705 | wp_new_user_notification( $user, null, $notify ); |
| 706 | |
| 707 | /** |
| 708 | * Check to see if a notification email was sent to the |
| 709 | * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`. |
| 710 | */ |
| 711 | if ( isset( $GLOBALS['phpmailer']->mock_sent ) && ! empty( $GLOBALS['phpmailer']->mock_sent ) ) { |
| 712 | $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'admin@example.org' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) ? true : false; |
| 713 | $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] ) ? true : false; |
| 714 | } |
| 715 | |
| 716 | $this->assertSame( $admin_email_sent_expected, $was_admin_email_sent, 'Admin email result was not as expected in test_wp_new_user_notification' ); |
| 717 | $this->assertSame( $user_email_sent_expected , $was_user_email_sent, 'User email result was not as expected in test_wp_new_user_notification' ); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Data provider. |
| 722 | * |
| 723 | * Passes the three available options for the $notify parameter and the expected email |
| 724 | * emails sent status as a bool. |
| 725 | * |
| 726 | * @since 4.4.0 |
| 727 | * |
| 728 | * @return array { |
| 729 | * @type array { |
| 730 | * @type string $post_args The arguments that will merged with the $_POST array. |
| 731 | * @type bool $admin_email_sent_expected The expected result of whether an email was sent to the admin. |
| 732 | * @type bool $user_email_sent_expected The expected result of whether an email was sent to the user. |
| 733 | * } |
| 734 | * } |
| 735 | */ |
| 736 | function data_wp_new_user_notifications() { |
| 737 | |
| 738 | return array( |
| 739 | array( |
| 740 | '', |
| 741 | true, |
| 742 | false, |
| 743 | ), |
| 744 | array( |
| 745 | 'admin', |
| 746 | true, |
| 747 | false, |
| 748 | ), |
| 749 | array( |
| 750 | 'both', |
| 751 | true, |
| 752 | true, |
| 753 | ), |
| 754 | ); |
| 755 | } |