Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/12/2024 01:12:04 PM (3 years ago)
Author:
espellcaste
Message:

A BP_XProfile_Field update does not disassociate from its XProfile parent field.

This patch makes sure that when updating an existing XProfile field option using the save() method from the BP_XProfile_Field class,
the updated option has not the parent_id set to 0, thus becoming disassociated from its XProfile parent field.

Closes ​https://github.com/buddypress/buddypress/pull/267
Fixes #9130

File:
1 edited

Legend:

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

    r13314 r13792  
    699699
    700700        /**
     701         * @ticket BP9130
     702         */
     703        public function test_xprofile_update_keep_parent_id() {
     704                $g      = self::factory()->xprofile_group->create();
     705                $parent = self::factory()->xprofile_field->create( array(
     706                        'field_group_id' => $g,
     707                        'type'           => 'selectbox',
     708                        'name'           => 'Parent',
     709                ) );
     710
     711                $f = xprofile_insert_field(
     712                        array(
     713                                'field_group_id' => $g,
     714                                'parent_id'      => $parent,
     715                                'type'           => 'option',
     716                                'name'           => 'Option 1',
     717                                'option_order'   => 5,
     718                        )
     719                );
     720
     721                $field = new BP_XProfile_Field( $f );
     722
     723                $this->assertEquals( $parent, $field->parent_id );
     724                $this->assertNotEquals( 0, $field->parent_id );
     725
     726                $field->name = 'Option 2';
     727                $field->save(); // Perform the `UPDATE` query. The reason for the bug.
     728
     729                // Fetch the new DB value.
     730                $field = new BP_XProfile_Field( $f );
     731
     732                $this->assertNotEquals( 0, $field->parent_id );
     733                $this->assertEquals( $parent, $field->parent_id );
     734        }
     735
     736        /**
    701737         * @group xprofile_insert_field
    702738         */
Note: See TracChangeset for help on using the changeset viewer.