Skip to:
Content

BuddyPress.org

Ticket #6229: 6229.01.patch

File 6229.01.patch, 4.3 KB (added by johnjamesjacoby, 10 years ago)

Fix & Test

  • src/bp-notifications/bp-notifications-template.php

     
    205205        public $pag_page;
    206206
    207207        /**
     208         * The $_GET argument used in URLs for determining pagination
     209         *
     210         * @since BuddyPress (1.9.0)
     211         * @access public
     212         * @var int
     213         */
     214        public $pag_arg;
     215
     216        /**
    208217         * The number of items to display per page of results.
    209218         *
    210219         * @since BuddyPress (1.9.0)
     
    250259        public $sort_order;
    251260
    252261        /**
     262         * Array of variables used in this notification query
     263         *
     264         * @since BuddyPress (2.2.2)
     265         * @var array
     266         */
     267        public $query_vars;
     268
     269        /**
    253270         * Constructor method.
    254271         *
    255272         * @see bp_has_notifications() For information on the array format.
     
    267284                $r = wp_parse_args( $args, array(
    268285                        'id'                => false,
    269286                        'user_id'           => 0,
     287                        'item_id'           => false,
    270288                        'secondary_item_id' => false,
    271289                        'component_name'    => bp_notifications_get_registered_components(),
    272290                        'component_action'  => false,
     
    274292                        'search_terms'      => '',
    275293                        'order_by'          => 'date_notified',
    276294                        'sort_order'        => 'DESC',
     295                        'page_arg'          => 'npage',
    277296                        'page'              => 1,
    278297                        'per_page'          => 25,
    279298                        'max'               => null,
    280                         'page_arg'          => 'npage',
    281299                ) );
    282300
    283301                // Overrides
     
    299317                $this->search_terms = $r['search_terms'];
    300318                $this->order_by     = $r['order_by'];
    301319                $this->sort_order   = $r['sort_order'];
     320                $this->query_vars   = array(
     321                        'id'                => $r['id'],
     322                        'user_id'           => $this->user_id,
     323                        'item_id'           => $r['item_id'],
     324                        'secondary_item_id' => $r['secondary_item_id'],
     325                        'component_name'    => $r['component_name'],
     326                        'component_action'  => $r['component_action'],
     327                        'is_new'            => $this->is_new,
     328                        'search_terms'      => $this->search_terms,
     329                        'order_by'          => $this->order_by,
     330                        'sort_order'        => $this->sort_order,
     331                        'page'              => $this->pag_page,
     332                        'per_page'          => $this->pag_num,
     333                );
    302334
    303335                // Setup the notifications to loop through
    304                 $this->notifications            = BP_Notifications_Notification::get( $r );
    305                 $this->total_notification_count = BP_Notifications_Notification::get_total_count( $r );
     336                $this->notifications            = BP_Notifications_Notification::get( $this->query_vars );
     337                $this->total_notification_count = BP_Notifications_Notification::get_total_count( $this->query_vars );
    306338
    307339                if ( empty( $this->notifications ) ) {
    308340                        $this->notification_count       = 0;
  • tests/phpunit/testcases/notifications/class-bp-notifications-notification.php

     
    279279                $actual = wp_list_pluck( $n, 'id' );
    280280                $this->assertEquals( $expected, $actual );
    281281        }
     282       
     283        /**
     284         * @group pagination
     285         * @group BP6229
     286         */
     287        public function test_get_paged_sql() {
     288                $u = $this->factory->user->create();
     289                $this->factory->notification->create( array(
     290                        'component_name' => 'activity',
     291                        'secondary_item_id' => 1,
     292                        'user_id' => $u,
     293                        'is_new' => true,
     294                ) );
     295                $this->factory->notification->create( array(
     296                        'component_name' => 'activity',
     297                        'secondary_item_id' => 2,
     298                        'user_id' => $u,
     299                        'is_new' => true,
     300                ) );
     301                $this->factory->notification->create( array(
     302                        'component_name' => 'activity',
     303                        'secondary_item_id' => 3,
     304                        'user_id' => $u,
     305                        'is_new' => true,
     306                ) );
     307                $this->factory->notification->create( array(
     308                        'component_name' => 'activity',
     309                        'secondary_item_id' => 4,
     310                        'user_id' => $u,
     311                        'is_new' => true,
     312                ) );
     313                $this->factory->notification->create( array(
     314                        'component_name' => 'activity',
     315                        'secondary_item_id' => 5,
     316                        'user_id' => $u,
     317                        'is_new' => true,
     318                ) );
     319                $this->factory->notification->create( array(
     320                        'component_name' => 'activity',
     321                        'secondary_item_id' => 6,
     322                        'user_id' => $u,
     323                        'is_new' => true,
     324                ) );
     325
     326                $n = BP_Notifications_Notification::get( array(
     327                        'user_id' => $u,
     328                        'is_new' => true,
     329                        'page' => 2,
     330                        'per_page' => 4
     331                ) );
     332
     333                // Check that the correct number of items are pulled up
     334                $expected = 2;
     335                $actual = count( $n );
     336                $this->assertEquals( $expected, $actual );
     337        }
    282338}