Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2021 06:54:07 PM (5 years ago)
Author:
espellcaste
Message:

Adding support to paginate messages/recipients to the BP_Messages_Box_Template class.

When querying threads using the BP_Messages_Box_Template class, one might set a default of messages/recipients, instead of returning all items.

Fixes #8597

File:
1 edited

Legend:

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

    r13147 r13148  
    246246
    247247        /**
     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        /**
    248310         * @group get_recipients
    249311         */
Note: See TracChangeset for help on using the changeset viewer.