Skip to:
Content

BuddyPress.org

Changeset 8131


Ignore:
Timestamp:
03/14/2014 12:37:28 AM (11 years ago)
Author:
boonebgorges
Message:

Return an empty string from get_meta() functions when no value is found

BP get_meta() functions have been inconsistent about the type of value returned
when no match is found for the object_id+meta_key combination. In some cases,
we followed WP's get_metadata() and returned an empty string. In others, we
returned false.

This changeset aligns all of our get_meta() functions with WP in this regard,
returning an empty string when no matching value is found. A boolean false is
still returned when invalid arguments are passed to the functions.

Relevant unit tests have been updated, including strict assertSame() checking
where appropriate.

See #5399

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r8130 r8131  
    638638        }
    639639
    640         // If nothing was found, return false
     640        // If nothing was found, return empty string
    641641        if ( empty( $values ) ) {
    642             $retval = false;
     642            $retval = '';
    643643        } else {
    644644            $retval = $values;
    645645        }
    646     }
    647 
    648     // Legacy - On failure, expect false, not an empty string
    649     if ( '' === $retval ) {
    650         $retval = false;
    651646    }
    652647
  • trunk/tests/testcases/activity/class.BP_Activity_Activity.php

    r8125 r8131  
    6565
    6666        $meta = bp_activity_get_meta( $activity, 'Paul' );
    67         $this->assertFalse( $meta );
     67        $this->assertSame( '', $meta );
    6868    }
    6969
  • trunk/tests/testcases/activity/functions.php

    r8130 r8131  
    133133        bp_activity_update_meta( $a, $krazy_key, 'bar' );
    134134
    135         $this->assertEmpty( bp_activity_get_meta( $a, 'foo' ) );
     135        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
    136136    }
    137137
     
    155155        $a = $this->factory->activity->create();
    156156        bp_activity_update_meta( $a, 'foo', false );
    157         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ) );
     157        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
    158158    }
    159159
     
    164164    public function test_bp_activity_update_meta_new() {
    165165        $a = $this->factory->activity->create();
    166         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ), '"foo" meta should be empty for this activity item.' );
     166        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ), '"foo" meta should be empty for this activity item.' );
    167167        $this->assertTrue( bp_activity_update_meta( $a, 'foo', 'bar' ) );
    168168        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) );
     
    239239
    240240        $krazy_key = ' f!@#$%^o *(){}o?+';
    241         $this->assertEmpty( bp_activity_get_meta( $a, $krazy_key ) );
     241        $this->assertSame( '', bp_activity_get_meta( $a, $krazy_key ) );
    242242    }
    243243
     
    270270     * @group bp_activity_get_meta
    271271     * @group activitymeta
     272     * @ticket BP5399
    272273     */
    273274    public function test_bp_activity_get_meta_no_results_returns_false() {
    274275        $a = $this->factory->activity->create();
    275276
    276         // @todo this is a quirk
    277         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ) );
     277        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
    278278    }
    279279
     
    347347        bp_activity_update_meta( $a, 'foo', 'bar' );
    348348        $this->assertTrue( bp_activity_delete_meta( $a, 'foo', 'bar' ) );
    349         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ) );
     349        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
    350350    }
    351351
     
    359359        bp_activity_update_meta( $a, 'foo1', 'bar1' );
    360360        $this->assertTrue( bp_activity_delete_meta( $a ) );
    361         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ) );
    362         $this->assertFalse( bp_activity_get_meta( $a, 'foo1' ) );
     361        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
     362        $this->assertSame( '', bp_activity_get_meta( $a, 'foo1' ) );
    363363    }
    364364
     
    371371        bp_activity_update_meta( $a, 'foo', 'bar' );
    372372        $this->assertTrue( bp_activity_delete_meta( $a, 'foo', 'bar' ) );
    373         $this->assertFalse( bp_activity_get_meta( $a, 'foo' ) );
     373        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
    374374    }
    375375
     
    409409
    410410        $this->assertTrue( bp_activity_delete_meta( $a1, 'foo', '', true ) );
    411         $this->assertEmpty( '', bp_activity_get_meta( $a1, 'foo' ) );
    412         $this->assertEmpty( '', bp_activity_get_meta( $a2, 'foo' ) );
     411        $this->assertSame( '', bp_activity_get_meta( $a1, 'foo' ) );
     412        $this->assertSame( '', bp_activity_get_meta( $a2, 'foo' ) );
    413413        $this->assertSame( 'bar1', bp_activity_get_meta( $a1, 'foo1' ) );
    414414        $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) );
  • trunk/tests/testcases/blogs/functions.php

    r8130 r8131  
    9494
    9595        $this->assertTrue( bp_blogs_delete_blogmeta( 1, 'foo', '', true ) );
    96         $this->assertEmpty( '', bp_blogs_get_blogmeta( 1, 'foo' ) );
    97         $this->assertEmpty( '', bp_blogs_get_blogmeta( 2, 'foo' ) );
     96        $this->assertSame( '', bp_blogs_get_blogmeta( 1, 'foo' ) );
     97        $this->assertSame( '', bp_blogs_get_blogmeta( 2, 'foo' ) );
    9898        $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 1, 'foo1' ) );
    9999        $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) );
     
    117117        bp_blogs_update_blogmeta( 1, 'foo', 'bar' );
    118118        $krazy_key = ' f!@#$%^o *(){}o?+';
    119         $this->assertEmpty( bp_blogs_get_blogmeta( 1, $krazy_key ) );
     119        $this->assertSame( '', bp_blogs_get_blogmeta( 1, $krazy_key ) );
    120120    }
    121121
     
    175175        $krazy_key = ' f!@#$%^o *(){}o?+';
    176176        bp_blogs_update_blogmeta( 1, $krazy_key, 'bar' );
    177         $this->assertEmpty( bp_blogs_get_blogmeta( 1, 'foo' ) );
     177        $this->assertSame( '', bp_blogs_get_blogmeta( 1, 'foo' ) );
    178178    }
    179179
  • trunk/tests/testcases/groups/functions.php

    r8129 r8131  
    308308    public function test_groups_update_groupmeta_new() {
    309309        $g = $this->factory->group->create();
    310         $this->assertEquals( '', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be empty for this group.' );
     310        $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be empty for this group.' );
    311311        $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'bar' ) );
    312312        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) );
     
    365365
    366366        $krazy_key = ' f!@#$%^o *(){}o?+';
    367         $this->assertEmpty( groups_get_groupmeta( $g, $krazy_key ) );
     367        $this->assertSame( '', groups_get_groupmeta( $g, $krazy_key ) );
    368368    }
    369369
     
    509509
    510510        $this->assertTrue( groups_delete_groupmeta( $g1, 'foo', '', true ) );
    511         $this->assertEmpty( '', groups_get_groupmeta( $g1, 'foo' ) );
    512         $this->assertEmpty( '', groups_get_groupmeta( $g2, 'foo' ) );
     511        $this->assertSame( '', groups_get_groupmeta( $g1, 'foo' ) );
     512        $this->assertSame( '', groups_get_groupmeta( $g2, 'foo' ) );
    513513        $this->assertSame( 'bar1', groups_get_groupmeta( $g1, 'foo1' ) );
    514514        $this->assertSame( 'bar1', groups_get_groupmeta( $g2, 'foo1' ) );
  • trunk/tests/testcases/xprofile/functions.php

    r8130 r8131  
    221221        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    222222        $this->assertTrue( bp_xprofile_delete_meta( $g, 'group', 'foo', 'bar' ) );
    223         $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     223        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    224224    }
    225225
     
    237237        $this->assertTrue( bp_xprofile_delete_meta( $g, 'group' ) );
    238238
    239         $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    240         $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
     239        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     240        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
    241241    }
    242242
     
    276276
    277277        $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', 'foo', '', true ) );
    278         $this->assertEmpty( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) );
    279         $this->assertEmpty( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
     278        $this->assertSame( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) );
     279        $this->assertSame( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
    280280        $this->assertSame( 'bar1', bp_xprofile_get_meta( $g1, 'group', 'foo1' ) );
    281281        $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
     
    386386        $krazy_key = ' f!@#$%^o *(){}o?+';
    387387        bp_xprofile_update_meta( $g, 'group', $krazy_key, 'bar' );
    388         $this->assertEmpty( bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     388        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    389389    }
    390390
Note: See TracChangeset for help on using the changeset viewer.