<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36594] trunk/tests/phpunit: Tests: Add decorators to PHPMailer mock object.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36594">36594</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36594","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-02-20 03:40:49 +0000 (Sat, 20 Feb 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Add decorators to PHPMailer mock object.

The new `get_recipient()` and `get_sent()` methods greatly simplify the
syntax required when writing tests for `wp_mail()`.

Props welcher.
Fixes <a href="https://core.trac.wordpress.org/ticket/34161">#34161</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludesmockmailerphp">trunk/tests/phpunit/includes/mock-mailer.php</a></li>
<li><a href="#trunktestsphpunittestsmailphp">trunk/tests/phpunit/tests/mail.php</a></li>
<li><a href="#trunktestsphpunittestsuserphp">trunk/tests/phpunit/tests/user.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunitincludesmockmailerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/mock-mailer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/mock-mailer.php      2016-02-19 23:41:43 UTC (rev 36593)
+++ trunk/tests/phpunit/includes/mock-mailer.php        2016-02-20 03:40:49 UTC (rev 36594)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,13 +14,73 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function postSend() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->mock_sent[] = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'to'     => $this->to,
-                       'cc'     => $this->cc,
-                       'bcc'    => $this->bcc,
-                       'header' => $this->MIMEHeader,
-                       'body'   => $this->MIMEBody,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'to'      => $this->to,
+                       'cc'      => $this->cc,
+                       'bcc'     => $this->bcc,
+                       'header'  => $this->MIMEHeader,
+                       'subject' => $this->Subject,
+                       'body'    => $this->MIMEBody,
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return true;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Decorator to return the information for a sent mock.
+        *
+        * @since 4.5.0
+        *
+        * @param int $index Optional. Array index of mock_sent value.
+        * @return object
+        */
+       public function get_sent( $index = 0 ) {
+               $retval = false;
+               if ( isset( $this->mock_sent[ $index ] ) ) {
+                       $retval = (object) $this->mock_sent[ $index ];
+               }
+               return $retval;
+       }
+
+       /**
+        * Get a recipient for a sent mock.
+        *
+        * @since 4.5.0
+        *
+        * @param string $address_type    The type of address for the email such as to, cc or bcc.
+        * @param int    $mock_sent_index Optional. The sent_mock index we want to get the recipient for.
+        * @param int    $recipient_index Optional. The recipient index in the array.
+        * @return bool|object Returns object on success, or false if any of the indices don't exist.
+        */
+       public function get_recipient( $address_type, $mock_sent_index = 0, $recipient_index = 0 ) {
+               $retval = false;
+               $mock = $this->get_sent( $mock_sent_index );
+               if ( $mock ) {
+                       if ( isset( $mock->{$address_type}[ $recipient_index ] ) ) {
+                               $address_index = $mock->{$address_type}[ $recipient_index ];
+                               $recipient_data = array(
+                                       'address' => ( isset( $address_index[0] ) && ! empty( $address_index[0] ) ) ? $address_index[0] : 'No address set',
+                                       'name'    => ( isset( $address_index[1] ) && ! empty( $address_index[1] ) ) ? $address_index[1] : 'No name set',
+                               );
+
+                               $retval = (object) $recipient_data;
+                       }
+               }
+
+               return $retval;
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Helper method to return the global phpmailer instance defined in the bootstrap
+ *
+ * @since 4.4.0
+ *
+ * @return object|bool
+ */
+function tests_retrieve_phpmailer_instance() {
+       $mailer = false;
+       if ( isset( $GLOBALS['phpmailer'] ) ) {
+               $mailer = $GLOBALS['phpmailer'];
+       }
+       return $mailer;
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsmailphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/mail.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/mail.php        2016-02-19 23:41:43 UTC (rev 36593)
+++ trunk/tests/phpunit/tests/mail.php  2016-02-20 03:40:49 UTC (rev 36594)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,24 +71,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $body .= '------=_Part_4892_25692638.1192452070893--' . "\n";
</span><span class="cx" style="display: block; padding: 0 10px">                $body .= "\n";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                wp_mail($to, $subject, $body, $headers);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         wp_mail( $to, $subject, $body, $headers );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $mailer = tests_retrieve_phpmailer_instance();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // We need some better assertions here but these catch the failure for now.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
-               $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
-               $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $body, $mailer->get_sent()->body );
+               $this->assertTrue( strpos( $mailer->get_sent()->header, 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 );
+               $this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 17305
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_mail_rfc2822_addresses() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to = "Name <address@tld.com>";
-               $from = "Another Name <another_address@different-tld.com>";
-               $cc = "The Carbon Guy <cc@cc.com>";
-               $bcc = "The Blind Carbon Guy <bcc@bcc.com>";
-               $subject = "RFC2822 Testing";
-               $message = "My RFC822 Test Message";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to        = 'Name <address@tld.com>';
+               $from      = 'Another Name <another_address@different-tld.com>';
+               $cc        = 'The Carbon Guy <cc@cc.com>';
+               $bcc       = 'The Blind Carbon Guy <bcc@bcc.com>';
+               $subject   = 'RFC2822 Testing';
+               $message   = 'My RFC822 Test Message';
</ins><span class="cx" style="display: block; padding: 0 10px">                 $headers[] = "From: {$from}";
</span><span class="cx" style="display: block; padding: 0 10px">                $headers[] = "CC: {$cc}";
</span><span class="cx" style="display: block; padding: 0 10px">                $headers[] = "BCC: {$bcc}";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -97,58 +99,64 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer
</span><span class="cx" style="display: block; padding: 0 10px">                // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
-               $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);
-               $this->assertEquals('cc@cc.com', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]);
-               $this->assertEquals('The Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][1]);
-               $this->assertEquals('bcc@bcc.com', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);
-               $this->assertEquals('The Blind Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][1]);
-               $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               //retrieve the mailer instance
+               $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertEquals( 'address@tld.com',      $mailer->get_recipient( 'to' )->address );
+               $this->assertEquals( 'Name',                 $mailer->get_recipient( 'to' )->name );
+               $this->assertEquals( 'cc@cc.com',            $mailer->get_recipient( 'cc' )->address );
+               $this->assertEquals( 'The Carbon Guy',       $mailer->get_recipient( 'cc' )->name );
+               $this->assertEquals( 'bcc@bcc.com',          $mailer->get_recipient( 'bcc' )->address );
+               $this->assertEquals( 'The Blind Carbon Guy', $mailer->get_recipient( 'bcc' )->name );
+               $this->assertEquals( $message . "\n",        $mailer->get_sent()->body );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 17305
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_mail_multiple_rfc2822_to_addresses() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to = "Name <address@tld.com>, Another Name <another_address@different-tld.com>";
-               $subject = "RFC2822 Testing";
-               $message = "My RFC822 Test Message";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to      = 'Name <address@tld.com>, Another Name <another_address@different-tld.com>';
+               $subject = 'RFC2822 Testing';
+               $message = 'My RFC822 Test Message';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer
</span><span class="cx" style="display: block; padding: 0 10px">                // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
-               $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);
-               $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
-               $this->assertEquals('Another Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][1]);
-               $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertEquals( 'address@tld.com',                   $mailer->get_recipient( 'to' )->address );
+               $this->assertEquals( 'Name',                              $mailer->get_recipient( 'to' )->name );
+               $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address );
+               $this->assertEquals( 'Another Name',                      $mailer->get_recipient( 'to', 0, 1 )->name );
+               $this->assertEquals( $message . "\n",                     $mailer->get_sent()->body );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_mail_multiple_to_addresses() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to = "address@tld.com, another_address@different-tld.com";
-               $subject = "RFC2822 Testing";
-               $message = "My RFC822 Test Message";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to      = 'address@tld.com, another_address@different-tld.com';
+               $subject = 'RFC2822 Testing';
+               $message = 'My RFC822 Test Message';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
-               $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
-               $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertEquals( 'address@tld.com',                   $mailer->get_recipient( 'to' )->address );
+               $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address );
+               $this->assertEquals( $message . "\n",                     $mailer->get_sent()->body );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 18463
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_mail_to_address_no_name() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to = "<address@tld.com>";
-               $subject = "RFC2822 Testing";
-               $message = "My RFC822 Test Message";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to      = '<address@tld.com>';
+               $subject = 'RFC2822 Testing';
+               $message = 'My RFC822 Test Message';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
-               $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address );
+               $this->assertEquals( $message . "\n",    $mailer->get_sent()->body );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -169,90 +177,96 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_valid_from_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "From: Foo <bar@example.com>";
-               $expected = "From: Foo <bar@example.com>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'From: Foo <bar@example.com>';
+               $expected = 'From: Foo <bar@example.com>';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_empty_from_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "From: ";
-               $expected = "From: WordPress <wordpress@" . WP_TESTS_DOMAIN . ">";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'From: ';
+               $expected = 'From: WordPress <wordpress@' . WP_TESTS_DOMAIN . '>';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_empty_from_name_for_the_from_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "From: <wordpress@example.com>";
-               $expected = "From: WordPress <wordpress@example.com>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'From: <wordpress@example.com>';
+               $expected = 'From: WordPress <wordpress@example.com>';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_valid_content_type_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "Content-Type: text/html; charset=iso-8859-1";
-               $expected = "Content-Type: text/html; charset=iso-8859-1";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'Content-Type: text/html; charset=iso-8859-1';
+               $expected = 'Content-Type: text/html; charset=iso-8859-1';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_empty_content_type_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "Content-Type: ";
-               $expected = "Content-Type: text/plain; charset=UTF-8";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'Content-Type: ';
+               $expected = 'Content-Type: text/plain; charset=UTF-8';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 30266
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_mail_with_empty_charset_for_the_content_type_header() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $to       = "address@tld.com";
-               $subject  = "Testing";
-               $message  = "Test Message";
-               $headers  = "Content-Type: text/plain;";
-               $expected = "Content-Type: text/plain; charset=UTF-8";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $to       = 'address@tld.com';
+               $subject  = 'Testing';
+               $message  = 'Test Message';
+               $headers  = 'Content-Type: text/plain;';
+               $expected = 'Content-Type: text/plain; charset=UTF-8';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_mail( $to, $subject, $message, $headers );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], $expected ) > 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $mailer = tests_retrieve_phpmailer_instance();
+               $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function wp_mail_quoted_printable( $mailer ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user.php        2016-02-19 23:41:43 UTC (rev 36593)
+++ trunk/tests/phpunit/tests/user.php  2016-02-20 03:40:49 UTC (rev 36594)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1028,15 +1028,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_new_user_notification( self::$contrib_id, null, $notify );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $mailer = tests_retrieve_phpmailer_instance();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /*
</span><span class="cx" style="display: block; padding: 0 10px">                 * Check to see if a notification email was sent to the
</span><span class="cx" style="display: block; padding: 0 10px">                 * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                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] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $admin_email = $mailer->get_recipient( 'to' );
+               $was_admin_email_sent = $admin_email && WP_TESTS_EMAIL === $admin_email->address;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $user_email = $mailer->get_recipient( 'to', 1 );
+               $was_user_email_sent = $user_email && 'blackburn@battlefield3.com' == $user_email->address;
+
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSame( $admin_email_sent_expected, $was_admin_email_sent, 'Admin email result was not as expected in test_wp_new_user_notification' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $user_email_sent_expected , $was_user_email_sent, 'User email result was not as expected in test_wp_new_user_notification' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre>
</div>
</div>

</body>
</html>