Skip to:
Content

BuddyPress.org

Ticket #5860: 5860.01.patch

File 5860.01.patch, 1.7 KB (added by r-a-y, 11 years ago)
  • src/bp-xprofile/bp-xprofile-classes.php

     
    387387        public static function update_position( $field_group_id, $position ) {
    388388                global $wpdb, $bp;
    389389
    390                 if ( !is_numeric( $position ) )
     390                if ( !is_numeric( $position ) ) {
    391391                        return false;
     392                }
     393
     394                // purge profile field group cache
     395                wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
    392396
    393397                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
    394398        }
  • tests/phpunit/testcases/xprofile/functions.php

     
    614614
    615615                $this->assertEquals( 5, $field->option_order );
    616616        }
     617
     618        /**
     619         * @group xprofile_update_field_group_position
     620         * @group bp_profile_get_field_groups
     621         */
     622        public function test_bp_profile_get_field_groups_update_position() {
     623                $g1 = $this->factory->xprofile_group->create();
     624                $g2 = $this->factory->xprofile_group->create();
     625                $g3 = $this->factory->xprofile_group->create();
     626
     627                // prime the cache
     628                bp_profile_get_field_groups();
     629
     630                // switch the field group positions for the last two groups
     631                xprofile_update_field_group_position( $g2, 3 );
     632                xprofile_update_field_group_position( $g3, 2 );
     633
     634                // now refetch field groups
     635                $field_groups = bp_profile_get_field_groups();
     636
     637                // assert!
     638                $this->assertEquals( array( 1, $g1, $g3, $g2 ), wp_list_pluck( $field_groups, 'id' ) );
     639        }
    617640}