WordPress.org

Make WordPress Core

Ticket #24662: 24662.3.patch

File 24662.3.patch, 3.4 KB (added by ocean90, 5 years ago)

Align mock_sent and add $phpmailer to the list of global vars

  • trunk/includes/bootstrap.php

     
    1717global $table_prefix, $wp_embed, $wp_locale, $_wp_deprecated_widgets_callbacks, $wp_widget_factory;
    1818
    1919// These are still needed
    20 global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp;
     20global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer;
    2121
    2222if ( !is_readable( $config_file_path ) ) {
    2323        die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" );
     
    4141
    4242$multisite = (int) ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE );
    4343
     44// Override the PHPMailer
     45require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
     46$phpmailer = new MockPHPMailer();
     47
    4448system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
    4549
    4650if ( $multisite ) {
  • trunk/includes/mock-mailer.php

     
    11<?php
     2require_once( ABSPATH . '/wp-includes/class-phpmailer.php' );
    23
    3 require_once(ABSPATH . '/wp-includes/class-phpmailer.php');
    4 
    54class MockPHPMailer extends PHPMailer {
    65        var $mock_sent = array();
    76
    87        // override the Send function so it doesn't actually send anything
    98        function Send() {
    10                 if ( (count($this->to) + count($this->cc) + count($this->bcc)) < 1 ) {
    11                         $this->SetError( 'You must provide at least one recipient email address.' );
    12                         return false;
    13                 }
     9                try {
     10                        if ( ! $this->PreSend() )
     11                                return false;
    1412
    15                 // Set whether the message is multipart/alternative
    16                 if( ! empty($this->AltBody) )
    17                         $this->ContentType = 'multipart/alternative';
     13                        $this->mock_sent[] = array(
     14                                'to'     => $this->to,
     15                                'cc'     => $this->cc,
     16                                'bcc'    => $this->bcc,
     17                                'header' => $this->MIMEHeader,
     18                                'body'   => $this->MIMEBody,
     19                        );
    1820
    19                 $this->error_count = 0; // reset errors
    20                 $this->SetMessageType();
    21                 $header = $this->CreateHeader();
    22                 $body = $this->CreateBody();
    23 
    24                 if ( $body == '' ) {
    25                         $this->SetError( 'Message body empty' );
     21                        return true;
     22                } catch ( phpmailerException $e ) {
    2623                        return false;
    2724                }
    28 
    29                 $this->mock_sent[] = array(
    30                         'to' => $this->to,
    31                         'cc' => $this->cc,
    32                         'bcc' => $this->bcc,
    33                         'header' => $header,
    34                         'body' => $body,
    35                 );
    36 
    37                 return true;
    38     }
     25        }
    3926}
    40 
    41 ?>
  • trunk/tests/mail.php

     
    33/**
    44 * @group pluggable
    55 * @group mail
    6  * @ticket UT47
    76 */
    87class Tests_Mail extends WP_UnitTestCase {
    98        function setUp() {
     
    6564                // We need some better assertions here but these catch the failure for now.
    6665                $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
    6766                $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
    68                 $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=""') > 0);
     67                $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
    6968                unset( $_SERVER['SERVER_NAME'] );
    7069        }
    7170