Skip to:
Content

BuddyPress.org

Changeset 9710


Ignore:
Timestamp:
04/07/2015 12:38:10 AM (11 years ago)
Author:
boonebgorges
Message:

Process is_default_option properly in xprofile_insert_field() and BP_XProfile_Field::save().

Previously, it was being ignored, which meant there was no way to change
is_default_option within the API.

Fixes #6137.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r9625 r9710  
    284284        }
    285285
    286         if ( ! empty( $r['is_default_option'] ) ) {
    287                 $field->is_default_option = $r['is_default_option'];
    288         }
     286        $field->is_default_option = (bool) $r['is_default_option'];
    289287
    290288        if ( ! empty( $r['option_order'] ) ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r9671 r9710  
    277277
    278278                if ( $this->id != null ) {
    279                         $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d, option_order = %d, can_delete = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete, $this->id );
     279                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d, option_order = %d, can_delete = %d, is_default_option = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete, $this->is_default_option, $this->id );
    280280                } else {
    281                         $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order, option_order, can_delete ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d, %d, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete );
     281                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order, option_order, can_delete, is_default_option ) VALUES ( %d, %d, %s, %s, %s, %d, %s, %d, %d, %d, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete, $this->is_default_option );
    282282                }
    283283
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r9561 r9710  
    669669
    670670        /**
     671         * @group xprofile_insert_field
     672         * @ticket BP6137
     673         */
     674        public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_new_option() {
     675                $g = $this->factory->xprofile_group->create();
     676                $parent = $this->factory->xprofile_field->create( array(
     677                        'field_group_id' => $g,
     678                        'type' => 'selectbox',
     679                        'name' => 'Parent',
     680                ) );
     681
     682                $f = xprofile_insert_field( array(
     683                        'field_group_id' => $g,
     684                        'parent_id' => $parent,
     685                        'type' => 'option',
     686                        'name' => 'Option 1',
     687                        'field_order' => 5,
     688                        'is_default_option' => false,
     689                ) );
     690
     691                $this->assertNotEmpty( $f );
     692                $field = new BP_XProfile_Field( $f );
     693                $this->assertEquals( 0, $field->is_default_option );
     694        }
     695
     696        /**
     697         * @group xprofile_insert_field
     698         * @ticket BP6137
     699         */
     700        public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_new_option() {
     701                $g = $this->factory->xprofile_group->create();
     702                $parent = $this->factory->xprofile_field->create( array(
     703                        'field_group_id' => $g,
     704                        'type' => 'selectbox',
     705                        'name' => 'Parent',
     706                ) );
     707
     708                $f = xprofile_insert_field( array(
     709                        'field_group_id' => $g,
     710                        'parent_id' => $parent,
     711                        'type' => 'option',
     712                        'name' => 'Option 1',
     713                        'field_order' => 5,
     714                        'is_default_option' => true,
     715                ) );
     716
     717                $this->assertNotEmpty( $f );
     718                $field = new BP_XProfile_Field( $f );
     719                $this->assertEquals( 1, $field->is_default_option );
     720        }
     721
     722        /**
     723         * @group xprofile_insert_field
     724         * @ticket BP6137
     725         */
     726        public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_existing_option() {
     727                $g = $this->factory->xprofile_group->create();
     728                $parent = $this->factory->xprofile_field->create( array(
     729                        'field_group_id' => $g,
     730                        'type' => 'selectbox',
     731                        'name' => 'Parent',
     732                ) );
     733
     734                $f = xprofile_insert_field( array(
     735                        'field_group_id' => $g,
     736                        'parent_id' => $parent,
     737                        'type' => 'option',
     738                        'name' => 'Option 1',
     739                        'field_order' => 5,
     740                        'is_default_option' => true,
     741                ) );
     742
     743                $this->assertNotEmpty( $f );
     744                $field = new BP_XProfile_Field( $f );
     745                $this->assertEquals( 1, $field->is_default_option );
     746
     747                $f = xprofile_insert_field( array(
     748                        'field_id' => $f,
     749                        'field_group_id' => $g,
     750                        'type' => 'textbox',
     751                        'is_default_option' => false,
     752                ) );
     753
     754                $field2 = new BP_XProfile_Field( $f );
     755                $this->assertEquals( 0, $field2->is_default_option );
     756        }
     757
     758        /**
     759         * @group xprofile_insert_field
     760         * @ticket BP6137
     761         */
     762        public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_existing_option() {
     763                $g = $this->factory->xprofile_group->create();
     764                $parent = $this->factory->xprofile_field->create( array(
     765                        'field_group_id' => $g,
     766                        'type' => 'selectbox',
     767                        'name' => 'Parent',
     768                ) );
     769
     770                $f = xprofile_insert_field( array(
     771                        'field_group_id' => $g,
     772                        'parent_id' => $parent,
     773                        'type' => 'option',
     774                        'name' => 'Option 1',
     775                        'field_order' => 5,
     776                        'is_default_option' => false,
     777                ) );
     778
     779                $this->assertNotEmpty( $f );
     780                $field = new BP_XProfile_Field( $f );
     781                $this->assertEquals( 0, $field->is_default_option );
     782
     783                $f = xprofile_insert_field( array(
     784                        'field_id' => $f,
     785                        'field_group_id' => $g,
     786                        'type' => 'textbox',
     787                        'is_default_option' => true,
     788                ) );
     789
     790                $field2 = new BP_XProfile_Field( $f );
     791
     792                $this->assertEquals( 1, $field2->is_default_option );
     793        }
     794
     795        /**
    671796         * @group xprofile_update_field_group_position
    672797         * @group bp_profile_get_field_groups
Note: See TracChangeset for help on using the changeset viewer.