Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 07:02:16 PM (13 years ago)
Author:
boonebgorges
Message:

Add delete_all support for all _delete_meta() functions

The delete_all parameter allows you to delete all meta items matching the
specified meta_key, regardless of the associated object.

Because our meta delete functions also support the deletion of all metadata
associated with an object (by leaving out the meta_key param), a decision had
to be made regarding the behavior when _delete_meta() is called with delete_all

true and meta_key = false. The most logical (and least destructive) strategy

was deemed to be: force delete_all to false when meta_key is also false. This
ensures that you don't accidentally wipe out all metadata for a component.

See #5400

File:
1 edited

Legend:

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

    r7879 r7883  
    234234                $this->assertTrue( bp_xprofile_delete_meta( $g, 'group' ) );
    235235
    236                 // These will fail because of a caching bug
    237236                $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    238237                $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
     238        }
     239
     240        /**
     241         * @group xprofilemeta
     242         * @group bp_xprofile_delete_meta
     243         */
     244        public function test_bp_xprofile_delete_meta_with_delete_all_but_no_meta_key() {
     245                // With no meta key, don't delete for all items - just delete
     246                // all for a single item
     247                $g1 = $this->factory->xprofile_group->create();
     248                $g2 = $this->factory->xprofile_group->create();
     249                bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
     250                bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
     251                bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
     252                bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
     253
     254                $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', '', '', true ) );
     255                $this->assertEmpty( bp_xprofile_get_meta( $g1, 'group' ) );
     256                $this->assertSame( 'bar', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
     257                $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
     258        }
     259
     260        /**
     261         * @group xprofilemeta
     262         * @group bp_xprofile_delete_meta
     263         */
     264        public function test_bp_xprofile_delete_meta_with_delete_all() {
     265                // With no meta key, don't delete for all items - just delete
     266                // all for a single item
     267                $g1 = $this->factory->xprofile_group->create();
     268                $g2 = $this->factory->xprofile_group->create();
     269                bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
     270                bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
     271                bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
     272                bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
     273
     274                $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', 'foo', '', true ) );
     275                $this->assertEmpty( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) );
     276                $this->assertEmpty( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
     277                $this->assertSame( 'bar1', bp_xprofile_get_meta( $g1, 'group', 'foo1' ) );
     278                $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
    239279        }
    240280
Note: See TracChangeset for help on using the changeset viewer.