Skip to:
Content

BuddyPress.org

Ticket #5477: 5477-2.patch

File 5477-2.patch, 4.0 KB (added by dcavins, 12 years ago)
  • src/bp-groups/bp-groups-classes.php

    diff --git src/bp-groups/bp-groups-classes.php src/bp-groups/bp-groups-classes.php
    index 7121ea4..e53f30c 100644
    class BP_Groups_Group {  
    765765                        $sql[] = "ORDER BY {$orderby} {$order}";
    766766                }
    767767
    768                 if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) ) {
     768                if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) && $r['per_page'] != -1 ) {
    769769                        $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) );
    770770                }
    771771
  • tests/phpunit/testcases/groups/class-bp-groups-group.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php
    index 3cc7237..b3e5c5f 100644
    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase {  
    338338                $this->assertEquals( '1', $groups['total'] );
    339339        }
    340340
     341        /**
     342         * @group get
     343         * @ticket BP5477
     344         */
     345        public function test_get_groups_set_perpage_paged() {
     346                // Standard
     347                $time = time();
     348
     349                $g1 = $this->factory->group->create( array(
     350                        'name' => 'A Group',
     351                        'date_created' => bp_core_current_time(),
     352                ) );
     353                $g2 = $this->factory->group->create( array(
     354                        'name' => 'D Group',
     355                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
     356                ) );
     357                $g3 = $this->factory->group->create( array(
     358                        'name' => 'B Group',
     359                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100000 ),
     360                ) );
     361                $g4 = $this->factory->group->create( array(
     362                        'name' => 'C Group',
     363                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 1000 ),
     364                ) );
     365
     366                // If "per_page" and "page" are both set, should result in pagination being applied.
     367                $groups = BP_Groups_Group::get( array(
     368                        'per_page'      =>      2,
     369                        'page'          =>      1
     370                ) );
     371
     372                // Should return top 2 groups only
     373                $this->assertEquals( '2', count( $groups['groups'] ) );
     374        }
     375
     376        /**
     377         * @group get
     378         * @ticket BP5477
     379         */
     380        public function test_get_all_groups_null_page_perpage() {
     381                // Standard
     382                $time = time();
     383
     384                $g1 = $this->factory->group->create( array(
     385                        'name' => 'A Group',
     386                        'date_created' => bp_core_current_time(),
     387                ) );
     388                $g2 = $this->factory->group->create( array(
     389                        'name' => 'D Group',
     390                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
     391                ) );
     392                $g3 = $this->factory->group->create( array(
     393                        'name' => 'B Group',
     394                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100000 ),
     395                ) );
     396                $g4 = $this->factory->group->create( array(
     397                        'name' => 'C Group',
     398                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 1000 ),
     399                ) );
     400
     401                // Passing false to 'per_page' and 'page' should result in pagination not being applied
     402                $groups = BP_Groups_Group::get( array(
     403                        'per_page'      =>      false,
     404                        'page'          =>      false
     405                ) );
     406
     407                // Should return all groups; "paged" group total should be 4
     408                $this->assertEquals( '4', count( $groups['groups'] ) );
     409        }
     410
     411        /**
     412         * @group get
     413         * @ticket BP5477
     414         */
     415        public function test_get_all_groups_perpage_minus_one() {
     416                // Standard
     417                $time = time();
     418
     419                $g1 = $this->factory->group->create( array(
     420                        'name' => 'A Group',
     421                        'date_created' => bp_core_current_time(),
     422                ) );
     423                $g2 = $this->factory->group->create( array(
     424                        'name' => 'D Group',
     425                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
     426                ) );
     427                $g3 = $this->factory->group->create( array(
     428                        'name' => 'B Group',
     429                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100000 ),
     430                ) );
     431                $g4 = $this->factory->group->create( array(
     432                        'name' => 'C Group',
     433                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 1000 ),
     434                ) );
     435
     436                // Passing 'per_page' => -1 should result in pagination not being applied.
     437                $groups = BP_Groups_Group::get( array(
     438                        'per_page'      =>      -1
     439                ) );
     440
     441                // Should return all groups; "paged" group total should match 4
     442                $this->assertEquals( '4', count( $groups['groups'] ) );
     443        }
     444
    341445        /** convert_type_to_order_orderby() **********************************/
    342446
    343447        /**