Make WordPress Core

Changeset 1300 in tests


Ignore:
Timestamp:
06/29/2013 10:31:15 PM (10 years ago)
Author:
SergeyBiryukov
Message:

Re-implement the mock PHPMailer. props ocean90. fixes #24662.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/bootstrap.php

    r1232 r1300  
    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 ) ) {
     
    4141
    4242$multisite = (int) ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE );
     43
     44// Override the PHPMailer
     45require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
     46$phpmailer = new MockPHPMailer();
    4347
    4448system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
  • trunk/includes/mock-mailer.php

    r903 r1300  
    11<?php
    2 
    3 require_once(ABSPATH . '/wp-includes/class-phpmailer.php');
     2require_once( ABSPATH . '/wp-includes/class-phpmailer.php' );
    43
    54class MockPHPMailer extends PHPMailer {
     
    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.' );
     9        try {
     10            if ( ! $this->PreSend() )
     11                return false;
     12
     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            );
     20
     21            return true;
     22        } catch ( phpmailerException $e ) {
    1223            return false;
    1324        }
    14 
    15         // Set whether the message is multipart/alternative
    16         if( ! empty($this->AltBody) )
    17             $this->ContentType = 'multipart/alternative';
    18 
    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' );
    26             return false;
    27         }
    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

    r909 r1300  
    44 * @group pluggable
    55 * @group mail
    6  * @ticket UT47
    76 */
    87class Tests_Mail extends WP_UnitTestCase {
     
    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    }
Note: See TracChangeset for help on using the changeset viewer.