Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/14/2014 12:37:28 AM (10 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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' ) );
Note: See TracChangeset for help on using the changeset viewer.