Skip to:
Content

BuddyPress.org


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

Improve parameter sanitization in xprofile_insert_field().

The overzealous empty() checks meant that it was impossible to set certain
values on existing fields to falsey values.

Fixes #6354.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r9710 r9711  
    646646        /**
    647647         * @group xprofile_insert_field
     648         * @ticket BP6354
     649         */
     650        public function test_xprofile_insert_field_should_process_falsey_values_for_boolean_params_on_existing_fields() {
     651                $g = $this->factory->xprofile_group->create();
     652                $f = xprofile_insert_field( array(
     653                        'field_group_id' => $g,
     654                        'type' => 'textbox',
     655                        'name' => 'Foo',
     656                        'is_required' => true,
     657                        'can_delete' => true,
     658                        'is_default_option' => true,
     659                        'parent_id' => 13,
     660                        'field_order' => 5,
     661                        'option_order' => 8,
     662                        'description' => 'foo',
     663                        'order_by' => 'custom',
     664                ) );
     665
     666                $this->assertNotEmpty( $f );
     667
     668                $field = new BP_XProfile_Field( $f );
     669                $this->assertEquals( 1, $field->is_required );
     670                $this->assertEquals( 1, $field->can_delete );
     671                $this->assertEquals( 1, $field->is_default_option );
     672                $this->assertEquals( 13, $field->parent_id );
     673                $this->assertEquals( 5, $field->field_order );
     674                $this->assertEquals( 8, $field->option_order );
     675                $this->assertEquals( 'foo', $field->description );
     676                $this->assertEquals( 'custom', $field->order_by );
     677
     678                $f = xprofile_insert_field( array(
     679                        'field_group_id' => $g,
     680                        'type' => 'textbox',
     681                        'name' => 'Foo',
     682                        'is_required' => false,
     683                        'can_delete' => false,
     684                        'is_default_option' => false,
     685                        'parent_id' => 0,
     686                        'field_order' => 0,
     687                        'option_order' => 0,
     688                        'description' => '',
     689                        'order_by' => '',
     690                ) );
     691
     692                $this->assertNotEmpty( $f );
     693
     694                $field = new BP_XProfile_Field( $f );
     695                $this->assertEquals( 0, $field->is_required );
     696                $this->assertEquals( 0, $field->can_delete );
     697                $this->assertEquals( 0, $field->is_default_option );
     698                $this->assertEquals( 0, $field->parent_id );
     699                $this->assertEquals( 0, $field->field_order );
     700                $this->assertEquals( 0, $field->option_order );
     701                $this->assertEquals( '', $field->description );
     702                $this->assertEquals( '', $field->order_by );
     703        }
     704
     705        /**
     706         * @group xprofile_insert_field
    648707         */
    649708        public function test_xprofile_insert_field_type_option_option_order() {
Note: See TracChangeset for help on using the changeset viewer.