diff --git src/bp-groups/bp-groups-classes.php src/bp-groups/bp-groups-classes.php
index 7121ea4..e53f30c 100644
|
|
|
class BP_Groups_Group {
|
| 765 | 765 | $sql[] = "ORDER BY {$orderby} {$order}"; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | | if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) ) { |
| | 768 | if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) && $r['per_page'] != -1 ) { |
| 769 | 769 | $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ); |
| 770 | 770 | } |
| 771 | 771 | |
diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php
index 3cc7237..1a3476b 100644
|
|
|
class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase {
|
| 338 | 338 | $this->assertEquals( '1', $groups['total'] ); |
| 339 | 339 | } |
| 340 | 340 | |
| | 341 | /** |
| | 342 | * @group get |
| | 343 | * @ticket BP5477 |
| | 344 | */ |
| | 345 | public function test_get_groups_page_perpage_params() { |
| | 346 | // Create more than 20 groups (20 is the default per_page number) |
| | 347 | $group_ids = array(); |
| | 348 | |
| | 349 | for ( $i = 1; $i <= 25; $i++ ) { |
| | 350 | $group_ids[] = $this->factory->group->create(); |
| | 351 | } |
| | 352 | |
| | 353 | // Tests |
| | 354 | // Passing false to 'per_page' and 'page' should result in pagination not being applied |
| | 355 | $groups = BP_Groups_Group::get( array( |
| | 356 | 'per_page' => false, |
| | 357 | 'page' => false |
| | 358 | ) ); |
| | 359 | |
| | 360 | // Should return all groups; "paged" group total should be 25 |
| | 361 | $this->assertEquals( count( $group_ids ), count( $groups['groups'] ) ); |
| | 362 | |
| | 363 | unset( $groups ); |
| | 364 | |
| | 365 | // Passing 'per_page' => -1 should result in pagination not being applied. |
| | 366 | $groups = BP_Groups_Group::get( array( |
| | 367 | 'per_page' => -1 |
| | 368 | ) ); |
| | 369 | |
| | 370 | // Should return all groups; "paged" group total should match 25 |
| | 371 | $this->assertEquals( count( $group_ids ), count( $groups['groups'] ) ); |
| | 372 | |
| | 373 | unset( $groups ); |
| | 374 | |
| | 375 | // If "per_page" and "page" are both set, should result in pagination being applied. |
| | 376 | $groups = BP_Groups_Group::get( array( |
| | 377 | 'per_page' => 12, |
| | 378 | 'page' => 1 |
| | 379 | ) ); |
| | 380 | |
| | 381 | // Should return top 12 groups only |
| | 382 | $this->assertEquals( '12', count( $groups['groups'] ) ); |
| | 383 | } |
| | 384 | |
| 341 | 385 | /** convert_type_to_order_orderby() **********************************/ |
| 342 | 386 | |
| 343 | 387 | /** |