Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/13/2014 07:27:20 PM (12 years ago)
Author:
boonebgorges
Message:

Add support for disabling pagination in BP_Groups_Group::get() by passing per_page=-1

Also adds supporting unit tests.

Fixes #5477

Props dcavins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php

    r8499 r8829  
    339339        }
    340340
     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
    341385        /** convert_type_to_order_orderby() **********************************/
    342386
Note: See TracChangeset for help on using the changeset viewer.