Ticket #6229: 6229.01.patch
File 6229.01.patch, 4.3 KB (added by , 10 years ago) |
---|
-
src/bp-notifications/bp-notifications-template.php
205 205 public $pag_page; 206 206 207 207 /** 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 /** 208 217 * The number of items to display per page of results. 209 218 * 210 219 * @since BuddyPress (1.9.0) … … 250 259 public $sort_order; 251 260 252 261 /** 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 /** 253 270 * Constructor method. 254 271 * 255 272 * @see bp_has_notifications() For information on the array format. … … 267 284 $r = wp_parse_args( $args, array( 268 285 'id' => false, 269 286 'user_id' => 0, 287 'item_id' => false, 270 288 'secondary_item_id' => false, 271 289 'component_name' => bp_notifications_get_registered_components(), 272 290 'component_action' => false, … … 274 292 'search_terms' => '', 275 293 'order_by' => 'date_notified', 276 294 'sort_order' => 'DESC', 295 'page_arg' => 'npage', 277 296 'page' => 1, 278 297 'per_page' => 25, 279 298 'max' => null, 280 'page_arg' => 'npage',281 299 ) ); 282 300 283 301 // Overrides … … 299 317 $this->search_terms = $r['search_terms']; 300 318 $this->order_by = $r['order_by']; 301 319 $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 ); 302 334 303 335 // 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 ); 306 338 307 339 if ( empty( $this->notifications ) ) { 308 340 $this->notification_count = 0; -
tests/phpunit/testcases/notifications/class-bp-notifications-notification.php
279 279 $actual = wp_list_pluck( $n, 'id' ); 280 280 $this->assertEquals( $expected, $actual ); 281 281 } 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 } 282 338 }