Skip to:
Content

BuddyPress.org

Changeset 7664


Ignore:
Timestamp:
12/12/2013 08:43:28 PM (11 years ago)
Author:
boonebgorges
Message:

Always fake $_SERVERSERVER_NAME? when invoking wp_mail() during tests

This is a blanket fix for PHP errors that otherwise arise when calling any BP
function that results in an email notification being sent.

Location:
trunk/tests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/includes/testcase.php

    r7497 r7664  
    1212
    1313    protected $temp_has_bp_moderate = array();
     14    protected $cached_SERVER_NAME = null;
    1415
    1516    public function setUp() {
     
    2324        global $wpdb;
    2425        $wpdb->query( "TRUNCATE TABLE {$wpdb->users}" );
     26
     27        // Fake WP mail globals, to avoid errors
     28        add_filter( 'wp_mail', array( $this, 'setUp_wp_mail' ) );
     29        add_filter( 'wp_mail_from', array( $this, 'tearDown_wp_mail' ) );
    2530
    2631        $this->factory = new BP_UnitTest_Factory;
     
    305310     * Set up globals necessary to avoid errors when using wp_mail()
    306311     */
    307     public function setUp_wp_mail() {
     312    public function setUp_wp_mail( $args ) {
     313        if ( isset( $_SERVER['SERVER_NAME'] ) ) {
     314            $this->cached_SERVER_NAME = $_SERVER['SERVER_NAME'];
     315        }
     316
    308317        $_SERVER['SERVER_NAME'] = 'example.com';
     318
     319        // passthrough
     320        return $args;
    309321    }
    310322
     
    312324     * Tear down globals set up in setUp_wp_mail()
    313325     */
    314     public function tearDown_wp_mail() {
    315         unset( $_SERVER['SERVER_NAME'] );
     326    public function tearDown_wp_mail( $args ) {
     327        if ( ! empty( $this->cached_SERVER_NAME ) ) {
     328            $_SERVER['SERVER_NAME'] = $this->cached_SERVER_NAME;
     329            unset( $this->cached_SERVER_NAME );
     330        } else {
     331            unset( $_SERVER['SERVER_NAME'] );
     332        }
     333
     334        // passthrough
     335        return $args;
    316336    }
    317337}
  • trunk/tests/testcases/friends/class-bp-friends-friendship.php

    r7497 r7664  
    9393        $u1 = $this->create_user();
    9494        $u2 = $this->create_user();
    95 
    96         $this->setUp_wp_mail();
    9795        friends_add_friend( $u1, $u2, false );
    98         $this->tearDown_wp_mail();
    99 
    10096        $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
    10197    }
     
    107103        $u1 = $this->create_user();
    108104        $u2 = $this->create_user();
    109 
    110         $this->setUp_wp_mail();
    111105        friends_add_friend( $u1, $u2, false );
    112         $this->tearDown_wp_mail();
    113 
    114106        $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) );
    115107    }
  • trunk/tests/testcases/groups/functions.php

    r7500 r7664  
    227227        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    228228
    229         $this->setUp_wp_mail();
    230229        groups_send_membership_request( $u2, $g );
    231230        groups_accept_membership_request( 0, $u2, $g );
    232         $this->tearDown_wp_mail();
    233231
    234232        $this->assertEquals( 2, groups_get_groupmeta( $g, 'total_member_count' ) );
  • trunk/tests/testcases/members/template.php

    r7497 r7664  
    4545        $u2 = $this->create_user();
    4646
    47         $this->setUp_wp_mail();
    4847        friends_add_friend( $u1, $u2 );
    49         $this->tearDown_wp_mail();
    5048
    5149        $old_user = get_current_user_id();
Note: See TracChangeset for help on using the changeset viewer.