| 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 | |