Skip to:
Content

BuddyPress.org

Changeset 9140


Ignore:
Timestamp:
11/14/2014 02:01:22 PM (6 years ago)
Author:
boonebgorges
Message:

Move automated test mail handlers to setUpBeforeClass().

In many cases, creating data in BuddyPress (such as friendships) will generate
an email notification. In order to avoid errors when generating fixtures, our
automated suite places some filters on 'wp_mail'. However, these filters were
previously added during setUp(), which is too late for test classes that
create fixtures during setUpBeforeClass().

See #6009.

File:
1 edited

Legend:

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

    r9139 r9140  
    1212
    1313    protected $temp_has_bp_moderate = array();
    14     protected $cached_SERVER_NAME = null;
     14    protected static $cached_SERVER_NAME = null;
     15
     16    public static function setUpBeforeClass() {
     17        // Fake WP mail globals, to avoid errors
     18        add_filter( 'wp_mail', array( 'BP_UnitTestCase', 'setUp_wp_mail' ) );
     19        add_filter( 'wp_mail_from', array( 'BP_UnitTestCase', 'tearDown_wp_mail' ) );
     20    }
    1521
    1622    public function setUp() {
     
    3036        }
    3137
    32         // Fake WP mail globals, to avoid errors
    33         add_filter( 'wp_mail', array( $this, 'setUp_wp_mail' ) );
    34         add_filter( 'wp_mail_from', array( $this, 'tearDown_wp_mail' ) );
    3538
    3639        $this->factory = new BP_UnitTest_Factory;
     
    403406     * Set up globals necessary to avoid errors when using wp_mail()
    404407     */
    405     public function setUp_wp_mail( $args ) {
     408    public static function setUp_wp_mail( $args ) {
    406409        if ( isset( $_SERVER['SERVER_NAME'] ) ) {
    407             $this->cached_SERVER_NAME = $_SERVER['SERVER_NAME'];
     410            self::$cached_SERVER_NAME = $_SERVER['SERVER_NAME'];
    408411        }
    409412
     
    417420     * Tear down globals set up in setUp_wp_mail()
    418421     */
    419     public function tearDown_wp_mail( $args ) {
    420         if ( ! empty( $this->cached_SERVER_NAME ) ) {
    421             $_SERVER['SERVER_NAME'] = $this->cached_SERVER_NAME;
     422    public static function tearDown_wp_mail( $args ) {
     423        if ( ! empty( self::$cached_SERVER_NAME ) ) {
     424            $_SERVER['SERVER_NAME'] = self::$cached_SERVER_NAME;
    422425            unset( $this->cached_SERVER_NAME );
    423426        } else {
Note: See TracChangeset for help on using the changeset viewer.