Skip to:
Content

BuddyPress.org

Ticket #6658: 6658.01.patch

File 6658.01.patch, 1.9 KB (added by Offereins, 4 years ago)
  • src/bp-xprofile/classes/class-bp-xprofile-field.php

    diff --git a/src/bp-xprofile/classes/class-bp-xprofile-field.php b/src/bp-xprofile/classes/class-bp-xprofile-field.php
    index ce4a95a..e27980c 100644
    a b class BP_XProfile_Field { 
    360360                        return false;
    361361                }
    362362
     363                // Delete all metadata for this field.
     364                bp_xprofile_delete_meta( $this->id, 'field' );
     365
    363366                // Delete the data in the DB for this field.
    364367                if ( true === $delete_data ) {
    365368                        BP_XProfile_ProfileData::delete_for_field( $this->id );
  • tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    diff --git a/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php b/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php
    index ce7a07b..e06c22b 100644
    a b class BP_Tests_BP_XProfile_Field_TestCases extends BP_UnitTestCase { 
    224224
    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}