Ticket #36658: 36658.diff
File 36658.diff, 7.6 KB (added by , 8 years ago) |
---|
-
tests/phpunit/includes/mock-mailer.php
77 77 * 78 78 * @return object|bool 79 79 */ 80 function tests_retrieve_phpmailer_instance() {80 function retrieve_phpmailer_instance() { 81 81 $mailer = false; 82 82 if ( isset( $GLOBALS['phpmailer'] ) ) { 83 83 $mailer = $GLOBALS['phpmailer']; … … 84 84 } 85 85 return $mailer; 86 86 } 87 88 89 /** 90 * Helper method to reset the phpmailer instance. 91 * 92 * @since 4.6.0 93 * 94 * @return bool 95 */ 96 function reset_php_mailer_instance() { 97 $mailer = retrieve_phpmailer_instance(); 98 if ( $mailer && isset( $mailer->mock_sent ) ) { 99 unset( $mailer->mock_sent ); 100 return true; 101 } 102 103 return false; 104 } -
tests/phpunit/tests/comment.php
9 9 10 10 public function setUp() { 11 11 parent::setUp(); 12 unset( $GLOBALS['phpmailer']->mock_sent);12 reset_php_mailer_instance(); 13 13 } 14 14 15 15 public static function wpSetUpBeforeClass( $factory ) { … … 558 558 && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] 559 559 ) { 560 560 $email_sent_when_comment_added = true; 561 unset( $GLOBALS['phpmailer']->mock_sent);561 reset_php_mailer_instance(); 562 562 } else { 563 563 $email_sent_when_comment_added = false; 564 564 } … … 589 589 } else { 590 590 $email_sent_when_comment_approved = false; 591 591 } 592 unset( $GLOBALS['phpmailer']->mock_sent);592 reset_php_mailer_instance(); 593 593 594 594 // Post authors are notified when a new comment is added to their post. 595 595 $data = array( … … 607 607 ! empty( $GLOBALS['phpmailer']->mock_sent ) && 608 608 'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { 609 609 $email_sent_when_comment_added = true; 610 unset( $GLOBALS['phpmailer']->mock_sent);610 reset_php_mailer_instance(); 611 611 } else { 612 612 $email_sent_when_comment_added = false; 613 613 } -
tests/phpunit/tests/mail.php
6 6 class Tests_Mail extends WP_UnitTestCase { 7 7 function setUp() { 8 8 parent::setUp(); 9 unset( $GLOBALS['phpmailer']->mock_sent);9 reset_php_mailer_instance(); 10 10 } 11 11 12 12 function tearDown() { 13 unset( $GLOBALS['phpmailer']->mock_sent );14 13 parent::tearDown(); 14 reset_php_mailer_instance(); 15 15 } 16 16 17 17 /** … … 78 78 79 79 wp_mail( $to, $subject, $body, $headers ); 80 80 81 $mailer = tests_retrieve_phpmailer_instance();81 $mailer = retrieve_phpmailer_instance(); 82 82 83 83 // We need some better assertions here but these catch the failure for now. 84 84 $this->assertEquals( $body, $mailer->get_sent()->body ); … … 106 106 // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. 107 107 108 108 //retrieve the mailer instance 109 $mailer = tests_retrieve_phpmailer_instance();109 $mailer = retrieve_phpmailer_instance(); 110 110 $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); 111 111 $this->assertEquals( 'Name', $mailer->get_recipient( 'to' )->name ); 112 112 $this->assertEquals( 'cc@cc.com', $mailer->get_recipient( 'cc' )->address ); … … 128 128 129 129 // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer 130 130 // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. 131 $mailer = tests_retrieve_phpmailer_instance();131 $mailer = retrieve_phpmailer_instance(); 132 132 $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); 133 133 $this->assertEquals( 'Name', $mailer->get_recipient( 'to' )->name ); 134 134 $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address ); … … 143 143 144 144 wp_mail( $to, $subject, $message ); 145 145 146 $mailer = tests_retrieve_phpmailer_instance();146 $mailer = retrieve_phpmailer_instance(); 147 147 $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); 148 148 $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address ); 149 149 $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); … … 159 159 160 160 wp_mail( $to, $subject, $message ); 161 161 162 $mailer = tests_retrieve_phpmailer_instance();162 $mailer = retrieve_phpmailer_instance(); 163 163 $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); 164 164 $this->assertEquals( $message . "\n", $mailer->get_sent()->body ); 165 165 } … … 190 190 191 191 wp_mail( $to, $subject, $message, $headers ); 192 192 193 $mailer = tests_retrieve_phpmailer_instance();193 $mailer = retrieve_phpmailer_instance(); 194 194 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 195 195 } 196 196 … … 206 206 207 207 wp_mail( $to, $subject, $message, $headers ); 208 208 209 $mailer = tests_retrieve_phpmailer_instance();209 $mailer = retrieve_phpmailer_instance(); 210 210 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 211 211 } 212 212 … … 222 222 223 223 wp_mail( $to, $subject, $message, $headers ); 224 224 225 $mailer = tests_retrieve_phpmailer_instance();225 $mailer = retrieve_phpmailer_instance(); 226 226 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 227 227 } 228 228 … … 238 238 239 239 wp_mail( $to, $subject, $message, $headers ); 240 240 241 $mailer = tests_retrieve_phpmailer_instance();241 $mailer = retrieve_phpmailer_instance(); 242 242 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 243 243 } 244 244 … … 254 254 255 255 wp_mail( $to, $subject, $message, $headers ); 256 256 257 $mailer = tests_retrieve_phpmailer_instance();257 $mailer = retrieve_phpmailer_instance(); 258 258 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 259 259 } 260 260 … … 270 270 271 271 wp_mail( $to, $subject, $message, $headers ); 272 272 273 $mailer = tests_retrieve_phpmailer_instance();273 $mailer = retrieve_phpmailer_instance(); 274 274 $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 ); 275 275 } 276 276 -
tests/phpunit/tests/user.php
1024 1024 * @ticket 36009 1025 1025 */ 1026 1026 function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) { 1027 unset( $GLOBALS['phpmailer']->mock_sent);1027 reset_php_mailer_instance(); 1028 1028 1029 1029 $was_admin_email_sent = false; 1030 1030 $was_user_email_sent = false; … … 1031 1031 1032 1032 wp_new_user_notification( self::$contrib_id, null, $notify ); 1033 1033 1034 $mailer = tests_retrieve_phpmailer_instance();1034 $mailer = retrieve_phpmailer_instance(); 1035 1035 1036 1036 /* 1037 1037 * Check to see if a notification email was sent to the … … 1100 1100 * @expectedDeprecated wp_new_user_notification 1101 1101 */ 1102 1102 function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() { 1103 unset( $GLOBALS['phpmailer']->mock_sent);1103 reset_php_mailer_instance(); 1104 1104 1105 1105 $was_admin_email_sent = false; 1106 1106 $was_user_email_sent = false; … … 1125 1125 * @ticket 34377 1126 1126 */ 1127 1127 function test_wp_new_user_notification_old_signature_no_password() { 1128 unset( $GLOBALS['phpmailer']->mock_sent);1128 reset_php_mailer_instance(); 1129 1129 1130 1130 $was_admin_email_sent = false; 1131 1131 $was_user_email_sent = false;