[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/messages/ -> class.bp-messages-thread.php (source)

   1  <?php
   2  
   3  /**
   4   * @group BP_Messages_Thread
   5   * @group messages
   6   */
   7  class BP_Tests_BP_Messages_Thread extends BP_UnitTestCase {
   8  
   9      /**
  10       * @group cache
  11       */
  12  	public function construct_cache() {
  13          $u1 = self::factory()->user->create();
  14          $u2 = self::factory()->user->create();
  15  
  16          $message = self::factory()->message->create_and_get( array(
  17              'sender_id' => $u1,
  18              'recipients' => array( $u2 ),
  19              'subject' => 'Foo',
  20          ) );
  21  
  22          // prime cache
  23          new BP_Messages_Thread( $message->thread_id );
  24  
  25          // Cache should exist
  26          $this->assertThat(
  27              wp_cache_get( $message->thread_id, 'bp_messages_threads' ),
  28              $this->logicalNot( $this->equalTo( false ) ),
  29              'Message thread cache should exist.'
  30          );
  31      }
  32  
  33  	public function test_get_messages_with_invalid_thread_id() {
  34          $this->assertTrue( empty( BP_Messages_Thread::get_messages( 0 ) ) );
  35      }
  36  
  37  	public function test_get_messages_using_arguments() {
  38          $u1 = self::factory()->user->create();
  39          $u2 = self::factory()->user->create();
  40          $m1 = self::factory()->message->create_and_get( array(
  41              'sender_id' => $u1,
  42              'recipients' => array( $u2 ),
  43              'subject' => 'Foo',
  44          ) );
  45  
  46          self::factory()->message->create_many(
  47              98,
  48              array(
  49                  'thread_id' => $m1->thread_id,
  50                  'sender_id' => $u2,
  51                  'recipients' => array( $u1 ),
  52                  'subject' => 'Bar',
  53              )
  54          );
  55  
  56          // Last message
  57          self::factory()->message->create(
  58              array(
  59                  'thread_id' => $m1->thread_id,
  60                  'sender_id' => $u1,
  61                  'recipients' => array( $u2 ),
  62                  'subject' => 'Last Message',
  63              )
  64          );
  65  
  66          // Default results.
  67          $messages = BP_Messages_Thread::get_messages( $m1->thread_id );
  68          $this->assertTrue( 100 === count( $messages ) );
  69  
  70          // Get first 10 messages.
  71          $messages = BP_Messages_Thread::get_messages( $m1->thread_id, array( 'page' => 1, 'per_page' => 10 ) );
  72          $this->assertTrue( 10 === count( $messages ) );
  73  
  74          // Get first 10 messages differently.
  75          $thread = new BP_Messages_Thread( $m1->thread_id, 'ASC', array( 'page' => 1, 'per_page' => 10 ) );
  76          $this->assertTrue( 10 === count( $thread->messages ) );
  77  
  78          // Get all messages.
  79          $messages = BP_Messages_Thread::get_messages( $m1->thread_id, array( 'page' => null, 'per_page' => null ) );
  80          $this->assertTrue( 100 === count( $messages ) );
  81  
  82          // Get all mesages differently.
  83          $thread = new BP_Messages_Thread( $m1->thread_id, 'ASC', array( 'page' => null, 'per_page' => null ) );
  84          $this->assertTrue( 100 === count( $thread->messages ) );
  85  
  86          // Get last message.
  87          $messages = BP_Messages_Thread::get_messages( $m1->thread_id, array( 'page' => 100, 'per_page' => 1 ) );
  88          $this->assertTrue( 1 === count( $messages ) );
  89          $this->assertEquals( $u1, $messages[0]->sender_id );
  90          $this->assertEquals( 'Last Message', $messages[0]->subject );
  91      }
  92  
  93      /**
  94       * @group order
  95       */
  96  	public function test_construct_order_desc() {
  97          $u1 = self::factory()->user->create();
  98          $u2 = self::factory()->user->create();
  99  
 100          // create thread
 101          $message_1 = self::factory()->message->create_and_get( array(
 102              'sender_id'  => $u1,
 103              'recipients' => array( $u2 ),
 104              'subject'    => 'Foo',
 105          ) );
 106  
 107          // create reply
 108          $message_2 = self::factory()->message->create_and_get( array(
 109              'thread_id'  => $message_1->thread_id,
 110              'sender_id'  => $u1,
 111              'recipients' => array( $u2 ),
 112              'content'    => 'Bar'
 113          ) );
 114  
 115          // Default sort from constructor.
 116          $thread = new BP_Messages_Thread( $message_1->thread_id );
 117          $this->assertEquals(
 118              array( $message_1->id, $message_2->id ),
 119              wp_list_pluck( $thread->messages, 'id' )
 120          );
 121  
 122          // Default via the helper method.
 123          $messages = BP_Messages_Thread::get_messages( $message_1->thread_id );
 124          $this->assertEquals(
 125              array( $message_1->id, $message_2->id ),
 126              wp_list_pluck( $messages, 'id' )
 127          );
 128  
 129          // Now get thread by DESC via the constructor.
 130          $thread = new BP_Messages_Thread( $message_1->thread_id, 'DESC' );
 131          $this->assertEquals(
 132              array( $message_2->id, $message_1->id ),
 133              wp_list_pluck( $thread->messages, 'id' )
 134          );
 135  
 136          // Testing sort with lowercase.
 137          $thread = new BP_Messages_Thread( $message_1->thread_id, 'desc' );
 138          $this->assertEquals(
 139              array( $message_2->id, $message_1->id ),
 140              wp_list_pluck( $thread->messages, 'id' )
 141          );
 142  
 143          // Testing sort with lowercase and space.
 144          $thread = new BP_Messages_Thread( $message_1->thread_id, '    desc' );
 145          $this->assertEquals(
 146              array( $message_2->id, $message_1->id ),
 147              wp_list_pluck( $thread->messages, 'id' )
 148          );
 149  
 150          // Now sorting via the helper method.
 151          $messages = BP_Messages_Thread::get_messages( $message_1->thread_id, array( 'order' => 'desc' ) );
 152          $this->assertEquals(
 153              array( $message_2->id, $message_1->id ),
 154              wp_list_pluck( $messages, 'id' )
 155          );
 156      }
 157  
 158      /**
 159       * @group get_current_threads_for_user
 160       */
 161      public function test_get_current_threads_for_user_with_search_terms_inbox() {
 162          $u1 = self::factory()->user->create();
 163          $u2 = self::factory()->user->create();
 164  
 165          self::factory()->message->create_and_get( array(
 166              'sender_id' => $u1,
 167              'recipients' => array( $u2 ),
 168              'subject' => 'Foo',
 169          ) );
 170  
 171          $message_2 = self::factory()->message->create_and_get( array(
 172              'sender_id' => $u1,
 173              'recipients' => array( $u2 ),
 174              'subject' => 'Bar',
 175          ) );
 176  
 177          $threads = BP_Messages_Thread::get_current_threads_for_user( array(
 178              'user_id' => $u2,
 179              'search_terms' => 'ar',
 180          ) );
 181  
 182          $expected = array( $message_2->thread_id );
 183          $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
 184  
 185          $this->assertSame( $expected, $found );
 186      }
 187  
 188      /**
 189       * @group get_current_threads_for_user
 190       */
 191      public function test_get_current_threads_for_user_with_search_terms_sentbox() {
 192          $u1 = self::factory()->user->create();
 193          $u2 = self::factory()->user->create();
 194  
 195          self::factory()->message->create_and_get( array(
 196              'sender_id' => $u1,
 197              'recipients' => array( $u2 ),
 198              'subject' => 'Foo',
 199          ) );
 200  
 201          $message_2 = self::factory()->message->create_and_get( array(
 202              'sender_id' => $u1,
 203              'recipients' => array( $u2 ),
 204              'subject' => 'Bar',
 205          ) );
 206  
 207          $threads = BP_Messages_Thread::get_current_threads_for_user( array(
 208              'user_id' => $u1,
 209              'box' => 'sentbox',
 210              'search_terms' => 'ar',
 211          ) );
 212  
 213          $expected = array( $message_2->thread_id );
 214          $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
 215  
 216          $this->assertSame( $expected, $found );
 217      }
 218  
 219      /**
 220       * @group get_current_threads_for_user
 221       * @expectedDeprecated BP_Messages_Thread::get_current_threads_for_user
 222       */
 223      public function test_get_current_threads_for_user_with_old_args() {
 224          $u1 = self::factory()->user->create();
 225          $u2 = self::factory()->user->create();
 226  
 227          self::factory()->message->create_and_get( array(
 228              'sender_id' => $u1,
 229              'recipients' => array( $u2 ),
 230              'subject' => 'Foo',
 231          ) );
 232  
 233          $message_2 = self::factory()->message->create_and_get( array(
 234              'sender_id' => $u1,
 235              'recipients' => array( $u2 ),
 236              'subject' => 'Bar',
 237          ) );
 238  
 239          $threads = BP_Messages_Thread::get_current_threads_for_user( $u1, 'sentbox', 'all', null, null, 'ar' );
 240  
 241          $expected = array( $message_2->thread_id );
 242          $found = wp_parse_id_list( wp_list_pluck( $threads['threads'], 'thread_id' ) );
 243  
 244          $this->assertSame( $expected, $found );
 245      }
 246  
 247      /**
 248       * @group get_current_threads_for_user
 249       */
 250      public function test_get_current_threads_setting_per_page_messages_and_recipients() {
 251          $u1 = self::factory()->user->create();
 252          $u2 = self::factory()->user->create();
 253  
 254          // create initial thread
 255          $message_1 = self::factory()->message->create_and_get(
 256              array(
 257                  'sender_id'  => $u1,
 258                  'recipients' => array( $u2 ),
 259              )
 260          );
 261  
 262          // create some replies to thread
 263          self::factory()->message->create_and_get(
 264              array(
 265                  'thread_id'  => $message_1->thread_id,
 266                  'sender_id'  => $u2,
 267                  'recipients' => array( $u1 ),
 268              )
 269          );
 270  
 271          self::factory()->message->create_and_get(
 272              array(
 273                  'thread_id'  => $message_1->thread_id,
 274                  'sender_id'  => $u2,
 275                  'recipients' => array( $u1 ),
 276              )
 277          );
 278  
 279          self::factory()->message->create_and_get(
 280              array(
 281                  'thread_id'  => $message_1->thread_id,
 282                  'sender_id'  => $u1,
 283                  'recipients' => array( $u2 ),
 284              )
 285          );
 286  
 287          $threads = BP_Messages_Thread::get_current_threads_for_user(
 288              array( 'user_id' => $u1 )
 289          )['threads'];
 290  
 291          $this->assertCount( 4, $threads[0]->messages );
 292          $this->assertCount( 2, $threads[0]->recipients );
 293  
 294          $threads = BP_Messages_Thread::get_current_threads_for_user(
 295              array(
 296                  'user_id'             => $u1,
 297                  'messages_page'       => 1,
 298                  'messages_per_page'   => 2,
 299                  'recipients_page'     => 1,
 300                  'recipients_per_page' => 1,
 301              )
 302          )['threads'];
 303  
 304          $this->assertCount( 2, $threads[0]->messages );
 305          $this->assertNotCount( 2, $threads[0]->recipients );
 306          $this->assertCount( 1, $threads[0]->recipients );
 307      }
 308  
 309      /**
 310       * @group get_recipients
 311       */
 312  	public function test_get_recipients_paginated() {
 313          $u1       = self::factory()->user->create();
 314          $user_ids = self::factory()->user->create_many( 9 );
 315          $m        = self::factory()->message->create_and_get( array(
 316              'sender_id'  => $u1,
 317              'recipients' => $user_ids,
 318              'subject'    => 'Foo',
 319          ) );
 320  
 321          $thread_1 = new BP_Messages_Thread( $m->thread_id );
 322          $this->assertTrue( 10 === count( $thread_1->get_recipients() ) );
 323  
 324          $thread_2 = new BP_Messages_Thread( $m->thread_id, 'ASC', array( 'recipients_page' => 1, 'recipients_per_page' => 5 ) );
 325          $this->assertTrue( 5 === count( $thread_2->recipients ) );
 326  
 327          $thread_3 = new BP_Messages_Thread( $m->thread_id );
 328          $this->assertTrue( 8 === count( $thread_3->get_recipients( $m->thread_id, array( 'recipients_page' => 1, 'recipients_per_page' => 8 ) ) ) );
 329      }
 330  
 331      /**
 332       * @group get_recipients
 333       * @group cache
 334       */
 335  	public function test_get_recipients_should_cache_its_values() {
 336          global $wpdb;
 337  
 338          $u1 = self::factory()->user->create();
 339          $u2 = self::factory()->user->create();
 340  
 341          $message = self::factory()->message->create_and_get( array(
 342              'sender_id' => $u1,
 343              'recipients' => array( $u2 ),
 344              'subject' => 'Foo',
 345          ) );
 346  
 347          $thread = new BP_Messages_Thread( $message->thread_id );
 348          $recipients = $thread->get_recipients();
 349  
 350          $num_queries = $wpdb->num_queries;
 351          $recipients_cached = $thread->get_recipients();
 352  
 353          $this->assertEquals( $recipients, $recipients_cached );
 354          $this->assertEquals( $num_queries, $wpdb->num_queries );
 355      }
 356  
 357      /**
 358       * @group get_recipients
 359       * @group cache
 360       */
 361      public function test_get_recipients_cache_should_be_busted_when_thread_message_is_sent() {
 362          global $wpdb;
 363  
 364          $u1 = self::factory()->user->create();
 365          $u2 = self::factory()->user->create();
 366  
 367          $message = self::factory()->message->create_and_get( array(
 368              'sender_id' => $u1,
 369              'recipients' => array( $u2 ),
 370              'subject' => 'Foo',
 371          ) );
 372  
 373          $thread = new BP_Messages_Thread( $message->thread_id );
 374          $thread->get_recipients();
 375  
 376          // Verify that the cache is populated.
 377          $num_queries = $wpdb->num_queries;
 378          $thread->get_recipients();
 379          $this->assertEquals( $num_queries, $wpdb->num_queries );
 380  
 381          messages_new_message( array(
 382              'sender_id' => $u2,
 383              'thread_id' => $message->thread_id,
 384              'recipients' => array( $u1 ),
 385              'subject' => 'Bar',
 386              'content' => 'Baz',
 387          ) );
 388  
 389          // Cache should be empty.
 390          $num_queries = $wpdb->num_queries;
 391          $thread->get_recipients();
 392          $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
 393      }
 394  
 395      /**
 396       * @group get_recipients
 397       * @group cache
 398       */
 399      public function test_get_recipients_cache_should_be_busted_when_single_thread_is_deleted() {
 400          global $wpdb;
 401  
 402          $u1 = self::factory()->user->create();
 403          $u2 = self::factory()->user->create();
 404  
 405          $message = self::factory()->message->create_and_get( array(
 406              'sender_id' => $u1,
 407              'recipients' => array( $u2 ),
 408              'subject' => 'Foo',
 409          ) );
 410  
 411          $t1 = $message->thread_id;
 412  
 413          $thread = new BP_Messages_Thread( $t1 );
 414          $thread->get_recipients();
 415  
 416          // Verify that the cache is populated.
 417          $num_queries = $wpdb->num_queries;
 418          $thread->get_recipients();
 419          $this->assertEquals( $num_queries, $wpdb->num_queries );
 420  
 421          messages_delete_thread( $t1 );
 422  
 423          // Cache should be empty.
 424          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
 425      }
 426  
 427      /**
 428       * @group get_recipients
 429       * @group cache
 430       */
 431      public function test_get_recipients_cache_should_be_busted_when_array_of_threads_is_deleted() {
 432          global $wpdb;
 433  
 434          $u1 = self::factory()->user->create();
 435          $u2 = self::factory()->user->create();
 436  
 437          $message = self::factory()->message->create_and_get( array(
 438              'sender_id' => $u1,
 439              'recipients' => array( $u2 ),
 440              'subject' => 'Foo',
 441          ) );
 442  
 443          $t1 = $message->thread_id;
 444  
 445          $thread = new BP_Messages_Thread( $t1 );
 446          $thread->get_recipients();
 447  
 448          // Verify that the cache is populated.
 449          $num_queries = $wpdb->num_queries;
 450          $thread->get_recipients();
 451          $this->assertEquals( $num_queries, $wpdb->num_queries );
 452  
 453          messages_delete_thread( array( $t1 ) );
 454  
 455          // Cache should be empty.
 456          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
 457      }
 458  
 459      /**
 460       * @group get_recipients
 461       * @group cache
 462       */
 463      public function test_get_recipients_cache_should_be_busted_when_thread_is_read() {
 464          global $wpdb;
 465  
 466          $u1 = self::factory()->user->create();
 467          $u2 = self::factory()->user->create();
 468  
 469          $message = self::factory()->message->create_and_get( array(
 470              'sender_id' => $u1,
 471              'recipients' => array( $u2 ),
 472              'subject' => 'Foo',
 473          ) );
 474  
 475          $t1 = $message->thread_id;
 476  
 477          $thread = new BP_Messages_Thread( $t1 );
 478          $recipients = $thread->get_recipients();
 479  
 480          // Verify that the cache is populated.
 481          $num_queries = $wpdb->num_queries;
 482          $recipients_cached = $thread->get_recipients();
 483          $this->assertEquals( $num_queries, $wpdb->num_queries );
 484  
 485          // Mark thread as read
 486          $current_user = get_current_user_id();
 487          $this->set_current_user( $u2 );
 488          messages_mark_thread_read( $t1 );
 489  
 490          // Cache should be empty.
 491          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
 492  
 493          $this->set_current_user( $current_user );
 494      }
 495  
 496      /**
 497       * @group cache
 498       */
 499      public function test_marking_a_thread_as_read_with_specific_user_id() {
 500          $u1      = self::factory()->user->create();
 501          $u2      = self::factory()->user->create();
 502          $message = self::factory()->message->create_and_get( array(
 503              'sender_id'  => $u1,
 504              'recipients' => array( $u2 ),
 505              'subject'    => 'Foo',
 506          ) );
 507  
 508          $thread_id = $message->thread_id;
 509  
 510          // Cache should be populated.
 511          $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
 512  
 513          // Mark thread as read.
 514          messages_mark_thread_read( $thread_id, $u2 );
 515  
 516          // Cache should be empty.
 517          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
 518  
 519          $thread = new BP_Messages_Thread( $thread_id );
 520  
 521          $this->assertFalse( (bool) $thread->unread_count );
 522          $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count );
 523          $this->assertFalse( (bool) $thread->recipients[ $u2 ]->unread_count );
 524      }
 525  
 526      /**
 527       * @group cache
 528       */
 529      public function test_marking_a_thread_as_unread_with_specific_user_id() {
 530          $u1      = self::factory()->user->create();
 531          $u2      = self::factory()->user->create();
 532          $message = self::factory()->message->create_and_get( array(
 533              'sender_id'  => $u1,
 534              'recipients' => array( $u2 ),
 535              'subject'    => 'Foo',
 536          ) );
 537  
 538          $thread_id = $message->thread_id;
 539  
 540          // Cache should be populated.
 541          $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
 542  
 543          // Mark thread as unread.
 544          messages_mark_thread_unread( $thread_id, $u2 );
 545  
 546          // Cache should be empty.
 547          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
 548  
 549          $thread = new BP_Messages_Thread( $thread_id );
 550  
 551          $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count );
 552          $this->assertTrue( (bool) $thread->recipients[ $u2 ]->unread_count );
 553      }
 554  
 555      /**
 556       * @group get_recipients
 557       * @group cache
 558       */
 559      public function test_get_recipients_cache_should_be_busted_when_thread_is_unread() {
 560          global $wpdb;
 561  
 562          $u1 = self::factory()->user->create();
 563          $u2 = self::factory()->user->create();
 564  
 565          $message = self::factory()->message->create_and_get( array(
 566              'sender_id' => $u1,
 567              'recipients' => array( $u2 ),
 568              'subject' => 'Foo',
 569          ) );
 570  
 571          $t1 = $message->thread_id;
 572  
 573          $thread = new BP_Messages_Thread( $t1 );
 574          $thread->get_recipients();
 575  
 576          // Verify that the cache is populated.
 577          $num_queries = $wpdb->num_queries;
 578          $thread->get_recipients();
 579          $this->assertEquals( $num_queries, $wpdb->num_queries );
 580  
 581          // Mark thread as unread
 582          $current_user = get_current_user_id();
 583          $this->set_current_user( $u2 );
 584          messages_mark_thread_unread( $t1 );
 585  
 586          // Cache should be empty.
 587          $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
 588  
 589          $this->set_current_user( $current_user );
 590      }
 591  
 592      /**
 593       * @group check_access
 594       */
 595  	public function test_check_access_valid_thread() {
 596          $u1 = self::factory()->user->create();
 597          $u2 = self::factory()->user->create();
 598  
 599          $message = self::factory()->message->create_and_get( array(
 600              'sender_id' => $u1,
 601              'recipients' => array( $u2 ),
 602              'subject' => 'Foo',
 603          ) );
 604  
 605          $t1 = $message->thread_id;
 606  
 607          // save recipient ID
 608          $thread = new BP_Messages_Thread( $t1 );
 609          $r1 = wp_list_pluck( $thread->recipients, 'id' );
 610          $r1 = array_pop( $r1 );
 611  
 612          $this->assertEquals( $r1, BP_Messages_Thread::check_access( $t1, $u1 ) );
 613      }
 614  
 615      /**
 616       * @group check_access
 617       */
 618  	public function test_check_access_invalid_thread() {
 619          $this->assertEquals( null, BP_Messages_Thread::check_access( 999, 1 ) );
 620      }
 621  
 622      /**
 623       * @group is_valid
 624       */
 625  	public function test_is_valid_valid_thread() {
 626          $u1 = self::factory()->user->create();
 627          $u2 = self::factory()->user->create();
 628  
 629          $message = self::factory()->message->create_and_get( array(
 630              'sender_id' => $u1,
 631              'recipients' => array( $u2 ),
 632              'subject' => 'Foo',
 633          ) );
 634  
 635          $t1 = $message->thread_id;
 636  
 637          $this->assertEquals( $t1, BP_Messages_Thread::is_valid( $t1 ) );
 638      }
 639  
 640      /**
 641       * @group is_valid
 642       */
 643  	public function test_is_valid_invalid_thread() {
 644          $this->assertEquals( null, BP_Messages_Thread::is_valid( 999 ) );
 645      }
 646  
 647      /**
 648       * @group last_message
 649       */
 650  	public function test_last_message_populated() {
 651          $u1 = self::factory()->user->create();
 652          $u2 = self::factory()->user->create();
 653  
 654          $date = bp_core_current_time();
 655  
 656          $message = self::factory()->message->create_and_get( array(
 657              'sender_id' => $u1,
 658              'recipients' => array( $u2 ),
 659              'subject' => 'Foo',
 660              'date_sent' => $date,
 661              'content' => 'Bar and baz.',
 662          ) );
 663  
 664          $t1 = $message->thread_id;
 665  
 666          $thread = new BP_Messages_Thread( $t1 );
 667  
 668          $this->assertNotNull( $thread->last_message_id );
 669          $this->assertEquals( 'Foo', $thread->last_message_subject );
 670          $this->assertEquals( $u1, $thread->last_sender_id );
 671          $this->assertEquals( $date, $thread->last_message_date );
 672          $this->assertEquals( 'Bar and baz.', $thread->last_message_content );
 673      }
 674  
 675      /**
 676       * @group exit
 677       * @ticket BP7540
 678       */
 679  	public function test_bp_messages_thread_exit() {
 680          $u1 = self::factory()->user->create();
 681          $u2 = self::factory()->user->create();
 682          $u3 = self::factory()->user->create();
 683  
 684          $message = self::factory()->message->create_and_get( array(
 685              'sender_id' => $u1,
 686              'recipients' => array( $u2, $u3 ),
 687              'subject' => 'Foo Bar',
 688              'date_sent' => bp_core_current_time(),
 689              'content' => 'Foo Bar is there.',
 690          ) );
 691  
 692          $t1 = $message->thread_id;
 693  
 694          $this->assertTrue( BP_Messages_Thread::exit_thread( $t1, $u3 ) );
 695      }
 696  
 697      /**
 698       * @group exit
 699       * @ticket BP7540
 700       */
 701      public function test_bp_messages_thread_exit_not_enough_recipients() {
 702          $u1 = self::factory()->user->create();
 703          $u2 = self::factory()->user->create();
 704  
 705          $message = self::factory()->message->create_and_get( array(
 706              'sender_id' => $u1,
 707              'recipients' => array( $u2 ),
 708              'subject' => 'Bar Foo',
 709              'date_sent' => bp_core_current_time(),
 710              'content' => 'Bar Foo is also there.',
 711          ) );
 712  
 713          $t1 = $message->thread_id;
 714  
 715          $this->assertFalse( BP_Messages_Thread::exit_thread( $t1, $u2 ) );
 716      }
 717  
 718      /**
 719       * @group exit
 720       * @ticket BP7540
 721       */
 722      public function test_bp_messages_thread_exit_not_one_of_recipients() {
 723          $u1 = self::factory()->user->create();
 724          $u2 = self::factory()->user->create();
 725          $u3 = self::factory()->user->create();
 726          $u4 = self::factory()->user->create();
 727  
 728          $message = self::factory()->message->create_and_get( array(
 729              'sender_id' => $u1,
 730              'recipients' => array( $u2, $u3 ),
 731              'subject' => 'Taz',
 732              'date_sent' => bp_core_current_time(),
 733              'content' => 'Where is Taz?',
 734          ) );
 735  
 736          $t1 = $message->thread_id;
 737  
 738          $this->assertFalse( BP_Messages_Thread::exit_thread( $t1, $u4 ) );
 739      }
 740  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1