Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/30/2016 05:29:28 PM (5 years ago)
Author:
boonebgorges
Message:

Update Messages tests to work after the changes in [11042].

See #7234.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php

    r10038 r11044  
    33/**
    44 * @group BP_Messages_Thread
     5 * @group messages
    56 */
    67class BP_Tests_BP_Messages_Thread extends BP_UnitTestCase {
     
    1314        $u2 = $this->factory->user->create();
    1415
    15         $t1 = $this->factory->message->create( array(
     16        $message = $this->factory->message->create_and_get( array(
    1617            'sender_id' => $u1,
    1718            'recipients' => array( $u2 ),
     
    2021
    2122        // prime cache
    22         new BP_Messages_Thread( $t1 );
     23        new BP_Messages_Thread( $message->thread_id );
    2324
    2425        // Cache should exist
    2526        $this->assertThat(
    26             wp_cache_get( $t1, 'bp_messages_threads' ),
     27            wp_cache_get( $message->thread_id, 'bp_messages_threads' ),
    2728            $this->logicalNot( $this->equalTo( false ) ),
    2829            'Message thread cache should exist.'
     
    3839
    3940        // create thread
    40         $t1 = $this->factory->message->create( array(
    41             'sender_id' => $u1,
    42             'recipients' => array( $u2 ),
    43             'subject' => 'Foo',
    44         ) );
    45         // save message ID
    46         $thread = new BP_Messages_Thread( $t1 );
    47         $m1 = wp_list_pluck( $thread->messages, 'id' );
    48         $m1 = array_pop( $m1 );
     41        $message_1 = $this->factory->message->create_and_get( array(
     42            'sender_id' => $u1,
     43            'recipients' => array( $u2 ),
     44            'subject' => 'Foo',
     45        ) );
     46        $m1 = $message_1->id;
    4947
    5048        // create reply
    51         $t2 = $this->factory->message->create( array(
    52             'thread_id' => $t1,
     49        $message_2 = $this->factory->message->create_and_get( array(
     50            'thread_id' => $message_1->thread_id,
    5351            'sender_id' => $u1,
    5452            'recipients' => array( $u2 ),
    5553            'content' => 'Bar'
    5654        ) );
    57         // save message ID
    58         $thread = new BP_Messages_Thread( $t1 );
    59         $m2 = wp_list_pluck( $thread->messages, 'id' );
    60         $m2 = array_pop( $m2 );
     55        $m2 = $message_2->id;
    6156
    6257        // now get thread by DESC
    63         $thread = new BP_Messages_Thread( $t1, 'DESC' );
     58        $thread = new BP_Messages_Thread( $message_1->thread_id, 'DESC' );
    6459
    6560        // assert!
     
    7772        $u2 = $this->factory->user->create();
    7873
    79         $t1 = $this->factory->message->create( array(
    80             'sender_id' => $u1,
    81             'recipients' => array( $u2 ),
    82             'subject' => 'Foo',
    83         ) );
    84 
    85         $t2 = $this->factory->message->create( array(
     74        $message_1 = $this->factory->message->create_and_get( array(
     75            'sender_id' => $u1,
     76            'recipients' => array( $u2 ),
     77            'subject' => 'Foo',
     78        ) );
     79
     80        $message_2 = $this->factory->message->create_and_get( array(
    8681            'sender_id' => $u1,
    8782            'recipients' => array( $u2 ),
     
    9489        ) );
    9590
    96         $expected = array( $t2 );
     91        $expected = array( $message_2->thread_id );
    9792        $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
    9893
     
    107102        $u2 = $this->factory->user->create();
    108103
    109         $t1 = $this->factory->message->create( array(
    110             'sender_id' => $u1,
    111             'recipients' => array( $u2 ),
    112             'subject' => 'Foo',
    113         ) );
    114 
    115         $t2 = $this->factory->message->create( array(
     104        $message_1 = $this->factory->message->create_and_get( array(
     105            'sender_id' => $u1,
     106            'recipients' => array( $u2 ),
     107            'subject' => 'Foo',
     108        ) );
     109
     110        $message_2 = $this->factory->message->create_and_get( array(
    116111            'sender_id' => $u1,
    117112            'recipients' => array( $u2 ),
     
    125120        ) );
    126121
    127         $expected = array( $t2 );
     122        $expected = array( $message_2->thread_id );
    128123        $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
    129124
     
    139134        $u2 = $this->factory->user->create();
    140135
    141         $t1 = $this->factory->message->create( array(
    142             'sender_id' => $u1,
    143             'recipients' => array( $u2 ),
    144             'subject' => 'Foo',
    145         ) );
    146 
    147         $t2 = $this->factory->message->create( array(
     136        $message_1 = $this->factory->message->create_and_get( array(
     137            'sender_id' => $u1,
     138            'recipients' => array( $u2 ),
     139            'subject' => 'Foo',
     140        ) );
     141
     142        $message_2 = $this->factory->message->create_and_get( array(
    148143            'sender_id' => $u1,
    149144            'recipients' => array( $u2 ),
     
    153148        $threads = BP_Messages_Thread::get_current_threads_for_user( $u1, 'sentbox', 'all', null, null, 'ar' );
    154149
    155         $expected = array( $t2 );
     150        $expected = array( $message_2->thread_id );
    156151        $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
    157152
     
    169164        $u2 = $this->factory->user->create();
    170165
    171         $t1 = $this->factory->message->create( array(
    172             'sender_id' => $u1,
    173             'recipients' => array( $u2 ),
    174             'subject' => 'Foo',
    175         ) );
    176 
    177         $thread = new BP_Messages_Thread( $t1 );
     166        $message = $this->factory->message->create_and_get( array(
     167            'sender_id' => $u1,
     168            'recipients' => array( $u2 ),
     169            'subject' => 'Foo',
     170        ) );
     171
     172        $thread = new BP_Messages_Thread( $message->thread_id );
    178173        $recipients = $thread->get_recipients();
    179174
     
    195190        $u2 = $this->factory->user->create();
    196191
    197         $t1 = $this->factory->message->create( array(
    198             'sender_id' => $u1,
    199             'recipients' => array( $u2 ),
    200             'subject' => 'Foo',
    201         ) );
    202 
    203         $thread = new BP_Messages_Thread( $t1 );
     192        $message = $this->factory->message->create_and_get( array(
     193            'sender_id' => $u1,
     194            'recipients' => array( $u2 ),
     195            'subject' => 'Foo',
     196        ) );
     197
     198        $thread = new BP_Messages_Thread( $message->thread_id );
    204199        $recipients = $thread->get_recipients();
    205200
     
    211206        messages_new_message( array(
    212207            'sender_id' => $u2,
    213             'thread_id' => $t1,
     208            'thread_id' => $message->thread_id,
    214209            'recipients' => array( $u1 ),
    215210            'subject' => 'Bar',
     
    233228        $u2 = $this->factory->user->create();
    234229
    235         $t1 = $this->factory->message->create( array(
    236             'sender_id' => $u1,
    237             'recipients' => array( $u2 ),
    238             'subject' => 'Foo',
    239         ) );
     230        $message = $this->factory->message->create_and_get( array(
     231            'sender_id' => $u1,
     232            'recipients' => array( $u2 ),
     233            'subject' => 'Foo',
     234        ) );
     235
     236        $t1 = $message->thread_id;
    240237
    241238        $thread = new BP_Messages_Thread( $t1 );
     
    263260        $u2 = $this->factory->user->create();
    264261
    265         $t1 = $this->factory->message->create( array(
    266             'sender_id' => $u1,
    267             'recipients' => array( $u2 ),
    268             'subject' => 'Foo',
    269         ) );
     262        $message = $this->factory->message->create_and_get( array(
     263            'sender_id' => $u1,
     264            'recipients' => array( $u2 ),
     265            'subject' => 'Foo',
     266        ) );
     267
     268        $t1 = $message->thread_id;
    270269
    271270        $thread = new BP_Messages_Thread( $t1 );
     
    293292        $u2 = $this->factory->user->create();
    294293
    295         $t1 = $this->factory->message->create( array(
    296             'sender_id' => $u1,
    297             'recipients' => array( $u2 ),
    298             'subject' => 'Foo',
    299         ) );
     294        $message = $this->factory->message->create_and_get( array(
     295            'sender_id' => $u1,
     296            'recipients' => array( $u2 ),
     297            'subject' => 'Foo',
     298        ) );
     299
     300        $t1 = $message->thread_id;
    300301
    301302        $thread = new BP_Messages_Thread( $t1 );
     
    328329        $u2 = $this->factory->user->create();
    329330
    330         $t1 = $this->factory->message->create( array(
    331             'sender_id' => $u1,
    332             'recipients' => array( $u2 ),
    333             'subject' => 'Foo',
    334         ) );
     331        $message = $this->factory->message->create_and_get( array(
     332            'sender_id' => $u1,
     333            'recipients' => array( $u2 ),
     334            'subject' => 'Foo',
     335        ) );
     336
     337        $t1 = $message->thread_id;
    335338
    336339        $thread = new BP_Messages_Thread( $t1 );
     
    360363        $u2 = $this->factory->user->create();
    361364
    362         $t1 = $this->factory->message->create( array(
    363             'sender_id' => $u1,
    364             'recipients' => array( $u2 ),
    365             'subject' => 'Foo',
    366         ) );
     365        $message = $this->factory->message->create_and_get( array(
     366            'sender_id' => $u1,
     367            'recipients' => array( $u2 ),
     368            'subject' => 'Foo',
     369        ) );
     370
     371        $t1 = $message->thread_id;
    367372
    368373        // save recipient ID
     
    388393        $u2 = $this->factory->user->create();
    389394
    390         $t1 = $this->factory->message->create( array(
    391             'sender_id' => $u1,
    392             'recipients' => array( $u2 ),
    393             'subject' => 'Foo',
    394         ) );
     395        $message = $this->factory->message->create_and_get( array(
     396            'sender_id' => $u1,
     397            'recipients' => array( $u2 ),
     398            'subject' => 'Foo',
     399        ) );
     400
     401        $t1 = $message->thread_id;
    395402
    396403        $this->assertEquals( $t1, BP_Messages_Thread::is_valid( $t1 ) );
     
    413420        $date = bp_core_current_time();
    414421
    415         $t1 = $this->factory->message->create( array(
     422        $message = $this->factory->message->create_and_get( array(
    416423            'sender_id' => $u1,
    417424            'recipients' => array( $u2 ),
     
    420427            'content' => 'Bar and baz.',
    421428        ) );
     429
     430        $t1 = $message->thread_id;
    422431
    423432        $thread = new BP_Messages_Thread( $t1 );
Note: See TracChangeset for help on using the changeset viewer.