Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/07/2018 07:04:13 AM (4 years ago)
Author:
offereins
Message:

XProfile: delete field metadata when a field is deleted

Previously, field metadata remained in the database after a profile field
was deleted. Using bp_xprofile_delete_meta() all field metadata will
now be deleted while all relevant metadata hooks are fired.

Adds unit tests for default and custom field metadata.

Fixes #6658.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    r11737 r11847  
    225225        $this->set_current_user( $old_user );
    226226    }
     227
     228    /**
     229     * @ticket BP6658
     230     */
     231    public function test_delete_field_should_delete_default_field_metadata() {
     232        $group = self::factory()->xprofile_group->create();
     233        $field = self::factory()->xprofile_field->create( array(
     234            'field_group_id' => $group
     235        ) );
     236
     237        $field_obj = new BP_XProfile_Field( $field );
     238        $field_obj->delete();
     239
     240        $value = bp_xprofile_get_meta( $field, 'field', 'default_visibility' );
     241        $this->assertEmpty( $value );
     242    }
     243
     244    /**
     245     * @ticket BP6658
     246     */
     247    public function test_delete_field_should_delete_custom_field_metadata() {
     248        $group = self::factory()->xprofile_group->create();
     249        $field = self::factory()->xprofile_field->create( array(
     250            'field_group_id' => $group
     251        ) );
     252
     253        bp_xprofile_update_meta( $field, 'field', 'custom', 'metadata' );
     254
     255        $field_obj = new BP_XProfile_Field( $field );
     256        $field_obj->delete();
     257
     258        $value = bp_xprofile_get_meta( $field, 'field', 'custom' );
     259        $this->assertEmpty( $value );
     260    }
    227261}
Note: See TracChangeset for help on using the changeset viewer.