Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/09/2014 12:57:16 AM (11 years ago)
Author:
boonebgorges
Message:

Unit tests for groupmeta functions.

Precursor for migrating to WP meta API. See #4551

File:
1 edited

Legend:

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

    r7664 r7833  
    284284        $this->assertEquals( $meta_value, groups_get_groupmeta( $g, 'linebreak_test' ) );
    285285    }
     286
     287    /**
     288     * @group groupmeta
     289     */
     290    public function test_groups_update_groupmeta_non_numeric_id() {
     291        $this->assertFalse( groups_update_groupmeta( 'foo', 'bar', 'baz' ) );
     292    }
     293
     294    /**
     295     * @group groupmeta
     296     */
     297    public function test_groups_update_groupmeta_stripslashes() {
     298        $g = $this->factory->group->create();
     299        $value = "This string is totally slashin\'!";
     300        groups_update_groupmeta( $g, 'foo', $value );
     301
     302        $this->assertSame( stripslashes( $value ), groups_get_groupmeta( $g, 'foo' ) );
     303    }
     304
     305    /**
     306     * @group groupmeta
     307     */
     308    public function test_groups_update_groupmeta_new() {
     309        $g = $this->factory->group->create();
     310        $this->assertEquals( '', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be empty for this group.' );
     311        $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'bar' ) );
     312        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) );
     313    }
     314
     315    /**
     316     * @group groupmeta
     317     */
     318    public function test_groups_update_groupmeta_existing() {
     319        $g = $this->factory->group->create();
     320        groups_update_groupmeta( $g, 'foo', 'bar' );
     321        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be set already for this group.' );
     322        $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'baz' ) );
     323        $this->assertSame( 'baz', groups_get_groupmeta( $g, 'foo' ) );
     324    }
     325
     326    /**
     327     * @group groupmeta
     328     */
     329    public function test_groups_update_groupmeta_existing_same_value() {
     330        $g = $this->factory->group->create();
     331        groups_update_groupmeta( $g, 'foo', 'bar' );
     332        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be set already for this group.' );
     333        $this->assertFalse( groups_update_groupmeta( $g, 'foo', 'bar' ) );
     334        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) );
     335    }
     336
     337    /**
     338     * @group groupmeta
     339     *
     340     * @todo Why do we do this?
     341     */
     342    public function test_groups_get_groupmeta_with_illegal_key_characters() {
     343        $g = $this->factory->group->create();
     344        groups_update_groupmeta( $g, 'foo', 'bar' );
     345
     346        $krazy_key = ' f!@#$%^o *(){}o?+';
     347        $this->assertSame( groups_get_groupmeta( $g, 'foo' ), groups_get_groupmeta( $g, $krazy_key ) );
     348    }
     349
     350    /**
     351     * @group groupmeta
     352     */
     353    public function test_groups_get_groupmeta_all_metas() {
     354        $g = $this->factory->group->create();
     355        groups_update_groupmeta( $g, 'foo', 'bar' );
     356        groups_update_groupmeta( $g, 'Boone', 'is cool' );
     357
     358        // There's likely some other keys (total_member_count etc)
     359        // Just check to make sure both of ours are there
     360        $metas = groups_get_groupmeta( $g );
     361        $count = count( $metas );
     362        $this->assertSame( 'bar', $metas[ $count - 2 ] );
     363        $this->assertSame( 'is cool', $metas[ $count - 1 ] );
     364    }
     365
     366    /**
     367     * @group groupmeta
     368     */
     369    public function test_groups_get_groupmeta_all_metas_empty() {
     370        $g = $this->factory->group->create();
     371
     372        // Get rid of any auto-created values
     373        groups_delete_groupmeta( $g );
     374
     375        $metas = groups_get_groupmeta( $g );
     376        $this->assertSame( array(), $metas );
     377    }
     378
     379    /**
     380     * @group groupmeta
     381     */
     382    public function test_groups_get_groupmeta_empty() {
     383        $g = $this->factory->group->create();
     384        $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ) );
     385    }
     386
     387    /**
     388     * @group groupmeta
     389     */
     390    public function test_groups_delete_groupmeta_non_numeric_id() {
     391        $this->assertFalse( groups_delete_groupmeta( 'foo', 'bar' ) );
     392    }
     393
     394    /**
     395     * @group groupmeta
     396     */
     397    public function test_groups_delete_groupmeta_with_illegal_key_characters() {
     398        $g = $this->factory->group->create();
     399        $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'bar' ), 'Value of "foo" should be set at this point.' );
     400
     401        $krazy_key = ' f!@#$%^o *(){}o?+';
     402        $this->assertTrue( groups_delete_groupmeta( $g, $krazy_key ) );
     403        $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ) );
     404    }
    286405}
Note: See TracChangeset for help on using the changeset viewer.