Skip to:
Content

BuddyPress.org

Changeset 7856


Ignore:
Timestamp:
02/12/2014 01:07:45 AM (11 years ago)
Author:
boonebgorges
Message:

Add unit tests for xprofile meta functions. See #4551

File:
1 edited

Legend:

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

    r7836 r7856  
    157157        $this->assertSame( 'adminsonly', xprofile_get_field_visibility_level( $f->id, $u ) );
    158158    }
     159
     160    /**
     161     * @group xprofilemeta
     162     * @group bp_xprofile_delete_meta
     163     */
     164    public function test_bp_xprofile_delete_meta_empty_object_id() {
     165        $this->assertFalse( bp_xprofile_delete_meta( '', 'group' ) );
     166    }
     167
     168    /**
     169     * @group xprofilemeta
     170     * @group bp_xprofile_delete_meta
     171     */
     172    public function test_bp_xprofile_delete_meta_empty_object_type() {
     173        $this->assertFalse( bp_xprofile_delete_meta( 1, '' ) );
     174    }
     175
     176    /**
     177     * @group xprofilemeta
     178     * @group bp_xprofile_delete_meta
     179     */
     180    public function test_bp_xprofile_delete_meta_illegal_object_type() {
     181        $this->assertFalse( bp_xprofile_delete_meta( 1, 'foo' ) );
     182    }
     183
     184    /**
     185     * @group xprofilemeta
     186     * @group bp_xprofile_delete_meta
     187     */
     188    public function test_bp_xprofile_delete_meta_illegal_characters() {
     189        $g = $this->factory->xprofile_group->create();
     190        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     191        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     192
     193        $krazy_key = ' f!@#$%^o *(){}o?+';
     194        $this->assertTrue( bp_xprofile_delete_meta( $g->id, 'group', 'foo' ) );
     195        $this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     196    }
     197
     198    /**
     199     * @group xprofilemeta
     200     * @group bp_xprofile_delete_meta
     201     */
     202    public function test_bp_xprofile_delete_meta_trim_meta_value() {
     203        $g = $this->factory->xprofile_group->create();
     204        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     205        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     206
     207        $this->assertTrue( bp_xprofile_delete_meta( $g->id, 'group', 'foo', ' bar  ' ) );
     208        $this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     209    }
     210
     211    /**
     212     * @group xprofilemeta
     213     * @group bp_xprofile_delete_meta
     214     */
     215    public function test_bp_xprofile_delete_meta_meta_value_match() {
     216        $g = $this->factory->xprofile_group->create();
     217        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     218        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     219        $this->assertTrue( bp_xprofile_delete_meta( $g->id, 'group', 'foo', 'bar' ) );
     220        $this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     221    }
     222
     223    /**
     224     * @group xprofilemeta
     225     * @group bp_xprofile_delete_meta
     226     */
     227    public function test_bp_xprofile_delete_meta_delete_all() {
     228        $g = $this->factory->xprofile_group->create();
     229        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     230        bp_xprofile_update_meta( $g->id, 'group', 'foo2', 'bar' );
     231        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     232        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo2' ) );
     233
     234        $this->assertTrue( bp_xprofile_delete_meta( $g->id, 'group' ) );
     235
     236        // These will fail because of a caching bug
     237        //$this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     238        //$this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo2' ) );
     239    }
     240
     241    /**
     242     * @group xprofilemeta
     243     * @group bp_xprofile_get_meta
     244     */
     245    public function test_bp_xprofile_get_meta_empty_object_id() {
     246        $this->assertFalse( bp_xprofile_get_meta( 0, 'group' ) );
     247    }
     248
     249    /**
     250     * @group xprofilemeta
     251     * @group bp_xprofile_get_meta
     252     */
     253    public function test_bp_xprofile_get_meta_empty_object_type() {
     254        $this->assertFalse( bp_xprofile_get_meta( 1, '' ) );
     255    }
     256
     257    /**
     258     * @group xprofilemeta
     259     * @group bp_xprofile_get_meta
     260     */
     261    public function test_bp_xprofile_get_meta_illegal_object_type() {
     262        $this->assertFalse( bp_xprofile_get_meta( 1, 'foo' ) );
     263    }
     264
     265    /**
     266     * @group xprofilemeta
     267     * @group bp_xprofile_get_meta
     268     */
     269    public function test_bp_xprofile_get_meta_no_meta_key() {
     270        $g = $this->factory->xprofile_group->create();
     271        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     272        bp_xprofile_update_meta( $g->id, 'group', 'foo2', 'bar' );
     273
     274        $expected = array( 'bar', 'bar', );
     275        $this->assertSame( $expected, bp_xprofile_get_meta( $g->id, 'group' ) );
     276    }
     277
     278    /**
     279     * @group xprofilemeta
     280     * @group bp_xprofile_get_meta
     281     */
     282    public function test_bp_xprofile_get_meta_no_meta_key_no_results() {
     283        $g = $this->factory->xprofile_group->create();
     284
     285        $expected = array();
     286        $this->assertSame( $expected, bp_xprofile_get_meta( $g->id, 'group' ) );
     287    }
     288
     289    /**
     290     * @group xprofilemeta
     291     * @group bp_xprofile_update_meta
     292     */
     293    public function test_bp_xprofile_update_meta_no_object_id() {
     294        $this->assertFalse( bp_xprofile_update_meta( 0, 'group', 'foo', 'bar' ) );
     295    }
     296
     297    /**
     298     * @group xprofilemeta
     299     * @group bp_xprofile_update_meta
     300     */
     301    public function test_bp_xprofile_update_meta_no_object_type() {
     302        $this->assertFalse( bp_xprofile_update_meta( 1, '', 'foo', 'bar' ) );
     303    }
     304
     305    /**
     306     * @group xprofilemeta
     307     * @group bp_xprofile_update_meta
     308     */
     309    public function test_bp_xprofile_update_meta_illegal_object_type() {
     310        $this->assertFalse( bp_xprofile_update_meta( 1, 'foo', 'foo', 'bar' ) );
     311    }
     312
     313    /**
     314     * @group xprofilemeta
     315     * @group bp_xprofile_update_meta
     316     */
     317    public function test_bp_xprofile_update_meta_illegal_characters() {
     318        $g = $this->factory->xprofile_group->create();
     319        $krazy_key = ' f!@#$%^o *(){}o?+';
     320        bp_xprofile_update_meta( $g->id, 'group', $krazy_key, 'bar' );
     321        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     322    }
     323
     324    /**
     325     * @group xprofilemeta
     326     * @group bp_xprofile_update_meta
     327     */
     328    public function test_bp_xprofile_update_meta_stripslashes() {
     329        $g = $this->factory->xprofile_group->create();
     330        $v = "Totally \'tubular\'";
     331        bp_xprofile_update_meta( $g->id, 'group', 'foo', $v );
     332        $this->assertSame( stripslashes( $v ), bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     333    }
     334
     335    /**
     336     * @group xprofilemeta
     337     * @group bp_xprofile_update_meta
     338     */
     339    public function test_bp_xprofile_update_meta_empty_value_delete() {
     340        $g = $this->factory->xprofile_group->create();
     341        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     342        bp_xprofile_update_meta( $g->id, 'group', 'foo', '' );
     343        $this->assertSame( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     344    }
     345
     346    /**
     347     * @group xprofilemeta
     348     * @group bp_xprofile_update_meta
     349     */
     350    public function test_bp_xprofile_update_meta_new() {
     351        $g = $this->factory->xprofile_group->create();
     352        $this->assertSame( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     353        $this->assertTrue( bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' ) );
     354        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     355    }
     356
     357    /**
     358     * @group xprofilemeta
     359     * @group bp_xprofile_update_meta
     360     */
     361    public function test_bp_xprofile_update_meta_existing() {
     362        $g = $this->factory->xprofile_group->create();
     363        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     364        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     365        $this->assertTrue( bp_xprofile_update_meta( $g->id, 'group', 'foo', 'baz' ) );
     366        $this->assertSame( 'baz', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     367    }
     368
     369    /**
     370     * @group xprofilemeta
     371     * @group bp_xprofile_update_meta
     372     */
     373    public function test_bp_xprofile_update_meta_same_value() {
     374        $g = $this->factory->xprofile_group->create();
     375        bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' );
     376        $this->assertSame( 'bar', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
     377        $this->assertFalse( bp_xprofile_update_meta( $g->id, 'group', 'foo', 'bar' ) );
     378    }
    159379}
Note: See TracChangeset for help on using the changeset viewer.