Skip to:
Content

BuddyPress.org

Ticket #5099: 5099.unittest.patch

File 5099.unittest.patch, 2.0 KB (added by r-a-y, 12 years ago)
  • tests/testcases/groups/class-bp-groups-group.php

    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 
    6161
    6262        /**
    6363         * @group get
     64         * @group group_meta_query
    6465         */
    6566        public function test_get_with_meta_query() {
    6667                $g1 = $this->factory->group->create();
    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 
    8182
    8283        /**
    8384         * @group get
     85         * @group group_meta_query
    8486         */
    8587        public function test_get_empty_meta_query() {
    8688                $g1 = $this->factory->group->create();
    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 
    254256                $this->assertEquals( array( $g2, $g4, $g3, $g1 ), $found );
    255257        }
    256258
     259        /**
     260         * @group get
     261         * @group group_meta_query
     262         */
     263        public function test_meta_query_and_total_groups() {
     264                $g1 = $this->factory->group->create( array(
     265                        'name' => 'A Group',
     266                        'date_created' => bp_core_current_time(),
     267                ) );
     268                $g2 = $this->factory->group->create( array(
     269                        'name' => 'D Group',
     270                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
     271                ) );
     272                $g3 = $this->factory->group->create( array(
     273                        'name' => 'B Group',
     274                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100000 ),
     275                ) );
     276                $g4 = $this->factory->group->create( array(
     277                        'name' => 'C Group',
     278                        'date_created' => gmdate( 'Y-m-d H:i:s', $time - 1000 ),
     279                ) );
     280
     281                // mark one group with the metakey 'supergroup'
     282                groups_update_groupmeta( $g1, 'supergroup', 1 );
     283
     284                // fetch groups with our 'supergroup' metakey
     285                $groups = BP_Groups_Group::get( array(
     286                        'meta_query' => array(
     287                                array(
     288                                        'key'     => 'supergroup',
     289                                        'compare' => 'EXISTS',
     290                                )
     291                        )
     292                ) );
     293
     294                // group total should match 1
     295                $this->assertEquals( '1', $groups['total'] );
     296        }
     297
    257298        /** convert_type_to_order_orderby() **********************************/
    258299
    259300        /**