Skip to:
Content

BuddyPress.org

Changeset 10541


Ignore:
Timestamp:
02/07/2016 12:01:24 PM (4 years ago)
Author:
djpaul
Message:

Unit Tests, Emails: don't un-hook core email actions for unit tests.

The missing default properties cause confusion when writing new tests, and the absence could cause a badly-written test to pass.
The change updates the affected unit tests to correctly handle the default properties.

See #6592

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/class-bp-email.php

    r10539 r10541  
    2020            'user_email'   => 'test2@example.com',
    2121        ) );
    22 
    23         remove_filter( 'bp_email_get_headers', 'bp_email_set_default_headers', 6, 4 );
    24         remove_filter( 'bp_email_get_tokens', 'bp_email_set_default_tokens', 6, 4 );
    25     }
    26 
    27     public function tearDown() {
    28         add_filter( 'bp_email_get_tokens', 'bp_email_set_default_tokens', 6, 4 );
    29         add_filter( 'bp_email_get_headers', 'bp_email_set_default_headers', 6, 4 );
    30         parent::tearDown();
    3122    }
    3223
     
    6859
    6960    public function test_tokens() {
    70         $original = array( 'test1' => 'hello', 'test2' => 'world' );
    71 
    72         $email = new BP_Email( 'activity-at-message' );
    73         $email->set_tokens( $original );
    74 
    75         $this->assertSame(
    76             array( 'test1', 'test2' ),
     61        $email          = new BP_Email( 'activity-at-message' );
     62        $default_tokens = $email->get_tokens();
     63        $tokens         = array( 'test1' => 'hello', 'test2' => 'world' );
     64
     65        $email->set_tokens( $tokens );
     66
     67        $this->assertSame(
     68            array_keys( $tokens + $default_tokens ),
    7769            array_keys( $email->get_tokens() )
    7870        );
    7971
    8072        $this->assertSame(
    81             array( 'hello', 'world' ),
     73            array_values( $tokens + $default_tokens ),
    8274            array_values( $email->get_tokens() )
    8375        );
     
    8577
    8678    public function test_headers() {
    87         $email = new BP_Email( 'activity-at-message' );
    88 
    89         $headers = array( 'custom_header' => 'custom_value' );
     79        $email           = new BP_Email( 'activity-at-message' );
     80        $default_headers = $email->get_headers();
     81        $headers         = array( 'custom_header' => 'custom_value' );
     82
    9083        $email->set_headers( $headers );
    91         $this->assertSame( $headers, $email->get_headers() );
     84
     85        $this->assertSame( $headers + $default_headers, $email->get_headers() );
    9286    }
    9387
     
    10195
    10296    public function test_invalid_characters_are_stripped_from_tokens() {
    103         $email = new BP_Email( 'activity-at-message' );
     97        $email          = new BP_Email( 'activity-at-message' );
     98        $default_tokens = $email->get_tokens();
     99
    104100        $email->set_tokens( array( 'te{st}1' => 'hello world' ) );
    105101
    106102        $this->assertSame(
    107             array( 'test1' ),
     103            array_keys( array( 'test1' => 'hello world' ) + $default_tokens ),
    108104            array_keys( $email->get_tokens() )
    109105        );
     
    133129
    134130    public function test_invalid_headers() {
    135         $email = new BP_Email( 'activity-at-message' );
    136 
    137         $headers = array( 'custom:header' => 'custom:value' );
     131        $email           = new BP_Email( 'activity-at-message' );
     132        $default_headers = $email->get_headers();
     133        $headers         = array( 'custom:header' => 'custom:value' );
     134
    138135        $email->set_headers( $headers );
    139         $this->assertNotSame( $headers, $email->get( 'headers' ) );
    140         $this->assertSame( array( 'customheader' => 'customvalue' ), $email->get_headers() );
     136
     137        $this->assertNotSame( $headers + $default_headers, $email->get( 'headers' ) );
     138        $this->assertSame( array( 'customheader' => 'customvalue' ) + $default_headers, $email->get( 'headers' ) );
    141139    }
    142140
Note: See TracChangeset for help on using the changeset viewer.