- Timestamp:
- 08/30/2016 05:29:28 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php
r10038 r11044 3 3 /** 4 4 * @group BP_Messages_Thread 5 * @group messages 5 6 */ 6 7 class BP_Tests_BP_Messages_Thread extends BP_UnitTestCase { … … 13 14 $u2 = $this->factory->user->create(); 14 15 15 $ t1 = $this->factory->message->create( array(16 $message = $this->factory->message->create_and_get( array( 16 17 'sender_id' => $u1, 17 18 'recipients' => array( $u2 ), … … 20 21 21 22 // prime cache 22 new BP_Messages_Thread( $ t1);23 new BP_Messages_Thread( $message->thread_id ); 23 24 24 25 // Cache should exist 25 26 $this->assertThat( 26 wp_cache_get( $ t1, 'bp_messages_threads' ),27 wp_cache_get( $message->thread_id, 'bp_messages_threads' ), 27 28 $this->logicalNot( $this->equalTo( false ) ), 28 29 'Message thread cache should exist.' … … 38 39 39 40 // 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; 49 47 50 48 // 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, 53 51 'sender_id' => $u1, 54 52 'recipients' => array( $u2 ), 55 53 'content' => 'Bar' 56 54 ) ); 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; 61 56 62 57 // now get thread by DESC 63 $thread = new BP_Messages_Thread( $ t1, 'DESC' );58 $thread = new BP_Messages_Thread( $message_1->thread_id, 'DESC' ); 64 59 65 60 // assert! … … 77 72 $u2 = $this->factory->user->create(); 78 73 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( 86 81 'sender_id' => $u1, 87 82 'recipients' => array( $u2 ), … … 94 89 ) ); 95 90 96 $expected = array( $ t2);91 $expected = array( $message_2->thread_id ); 97 92 $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) ); 98 93 … … 107 102 $u2 = $this->factory->user->create(); 108 103 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( 116 111 'sender_id' => $u1, 117 112 'recipients' => array( $u2 ), … … 125 120 ) ); 126 121 127 $expected = array( $ t2);122 $expected = array( $message_2->thread_id ); 128 123 $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) ); 129 124 … … 139 134 $u2 = $this->factory->user->create(); 140 135 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( 148 143 'sender_id' => $u1, 149 144 'recipients' => array( $u2 ), … … 153 148 $threads = BP_Messages_Thread::get_current_threads_for_user( $u1, 'sentbox', 'all', null, null, 'ar' ); 154 149 155 $expected = array( $ t2);150 $expected = array( $message_2->thread_id ); 156 151 $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) ); 157 152 … … 169 164 $u2 = $this->factory->user->create(); 170 165 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 ); 178 173 $recipients = $thread->get_recipients(); 179 174 … … 195 190 $u2 = $this->factory->user->create(); 196 191 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 ); 204 199 $recipients = $thread->get_recipients(); 205 200 … … 211 206 messages_new_message( array( 212 207 'sender_id' => $u2, 213 'thread_id' => $ t1,208 'thread_id' => $message->thread_id, 214 209 'recipients' => array( $u1 ), 215 210 'subject' => 'Bar', … … 233 228 $u2 = $this->factory->user->create(); 234 229 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; 240 237 241 238 $thread = new BP_Messages_Thread( $t1 ); … … 263 260 $u2 = $this->factory->user->create(); 264 261 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; 270 269 271 270 $thread = new BP_Messages_Thread( $t1 ); … … 293 292 $u2 = $this->factory->user->create(); 294 293 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; 300 301 301 302 $thread = new BP_Messages_Thread( $t1 ); … … 328 329 $u2 = $this->factory->user->create(); 329 330 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; 335 338 336 339 $thread = new BP_Messages_Thread( $t1 ); … … 360 363 $u2 = $this->factory->user->create(); 361 364 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; 367 372 368 373 // save recipient ID … … 388 393 $u2 = $this->factory->user->create(); 389 394 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; 395 402 396 403 $this->assertEquals( $t1, BP_Messages_Thread::is_valid( $t1 ) ); … … 413 420 $date = bp_core_current_time(); 414 421 415 $ t1 = $this->factory->message->create( array(422 $message = $this->factory->message->create_and_get( array( 416 423 'sender_id' => $u1, 417 424 'recipients' => array( $u2 ), … … 420 427 'content' => 'Bar and baz.', 421 428 ) ); 429 430 $t1 = $message->thread_id; 422 431 423 432 $thread = new BP_Messages_Thread( $t1 );
Note: See TracChangeset
for help on using the changeset viewer.