diff --git src/bp-notifications/bp-notifications-template.php src/bp-notifications/bp-notifications-template.php
index bb05797..7602ee0 100644
|
|
|
class BP_Notifications_Template { |
| 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) |
| … |
… |
class BP_Notifications_Template { |
| 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. |
| … |
… |
class BP_Notifications_Template { |
| 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, |
| … |
… |
class BP_Notifications_Template { |
| 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 |
| … |
… |
class BP_Notifications_Template { |
| 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; |
diff --git tests/phpunit/testcases/notifications/class-bp-notifications-notification.php tests/phpunit/testcases/notifications/class-bp-notifications-notification.php
index c495ae9..2b41571 100644
|
|
|
class BP_Tests_BP_Notifications_Notification_TestCases extends BP_UnitTestCase { |
| 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 | |
| | 290 | $notifications = array(); |
| | 291 | for ( $i = 1; $i <= 6; $i++ ) { |
| | 292 | $notifications[] = $this->factory->notification->create( array( |
| | 293 | 'component_name' => 'activity', |
| | 294 | 'secondary_item_id' => $i, |
| | 295 | 'user_id' => $u, |
| | 296 | 'is_new' => true, |
| | 297 | ) ); |
| | 298 | } |
| | 299 | |
| | 300 | $found = BP_Notifications_Notification::get( array( |
| | 301 | 'user_id' => $u, |
| | 302 | 'is_new' => true, |
| | 303 | 'page' => 2, |
| | 304 | 'per_page' => 2, |
| | 305 | 'order_by' => 'id', |
| | 306 | ) ); |
| | 307 | |
| | 308 | // Check that the correct number of items are pulled up |
| | 309 | $expected = array( $notifications[2], $notifications[3] ); |
| | 310 | $this->assertEquals( $expected, wp_list_pluck( $found, 'id' ) ); |
| | 311 | } |
| 282 | 312 | } |
diff --git tests/phpunit/testcases/notifications/class-bp-notifications-template.php tests/phpunit/testcases/notifications/class-bp-notifications-template.php
new file mode 100644
index 0000000..4eb65cf
|
-
|
+
|
|
| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group notifications |
| | 5 | * @group template |
| | 6 | */ |
| | 7 | |
| | 8 | class BP_Tests_Notifications_BPNotificationsTemplate extends BP_UnitTestCase { |
| | 9 | /** |
| | 10 | * @group pagination |
| | 11 | * @group BP6229 |
| | 12 | */ |
| | 13 | public function test_pagination_params_in_url_should_be_passed_to_query() { |
| | 14 | $u = $this->factory->user->create(); |
| | 15 | |
| | 16 | $notifications = array(); |
| | 17 | for ( $i = 1; $i <= 6; $i++ ) { |
| | 18 | $notifications[] = $this->factory->notification->create( array( |
| | 19 | 'component_name' => 'activity', |
| | 20 | 'secondary_item_id' => $i, |
| | 21 | 'user_id' => $u, |
| | 22 | 'is_new' => true, |
| | 23 | ) ); |
| | 24 | } |
| | 25 | |
| | 26 | $_REQUEST['npage'] = 2; |
| | 27 | |
| | 28 | $template = new BP_Notifications_Template( array( |
| | 29 | 'user_id' => $u, |
| | 30 | 'is_new' => true, |
| | 31 | 'per_page' => 2, |
| | 32 | 'order_by' => 'id', |
| | 33 | ) ); |
| | 34 | |
| | 35 | unset( $_REQUEST['npage'] ); |
| | 36 | |
| | 37 | // Check that the correct number of items are pulled up |
| | 38 | $expected = array( $notifications[3], $notifications[2] ); |
| | 39 | $this->assertEquals( $expected, wp_list_pluck( $template->notifications, 'id' ) ); |
| | 40 | } |
| | 41 | } |