[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 include_once BP_TESTS_DIR . '/assets/group-extensions.php'; 4 5 /** 6 * @group groups 7 * @group BP_Group_Extension 8 */ 9 class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 10 public function test_parse_legacy_properties() { 11 $class_name = 'BPTest_Group_Extension_Parse_Legacy_Properties'; 12 $class_slug = sanitize_title( $class_name ); 13 $e = new $class_name(); 14 $e->_register(); 15 16 // Test most items separately so we can ignore irrelevant props 17 $l = $e->_get_legacy_properties_converted(); 18 $this->assertEquals( $l['name'], $class_name ); 19 $this->assertEquals( $l['slug'], $class_slug ); 20 $this->assertEquals( $l['visibility'], 'private' ); 21 $this->assertEquals( $l['nav_item_position'], 63 ); 22 $this->assertEquals( $l['enable_nav_item'], true ); 23 $this->assertEquals( $l['nav_item_name'], $class_name . ' Nav' ); 24 $this->assertEquals( $l['display_hook'], 'foo_hook' ); 25 $this->assertEquals( $l['template_file'], 'foo_template' ); 26 27 // Build the screens array manually 28 $expected = array( 29 'create' => array( 30 'name' => $class_name . ' Create', 31 'slug' => $class_slug . '-create', 32 'position' => 58, 33 'enabled' => false, 34 ), 35 'edit' => array( 36 'name' => $class_name . ' Edit', 37 'slug' => $class_slug . '-edit', 38 'enabled' => false, 39 ), 40 'admin' => array( 41 'enabled' => true, 42 'metabox_context' => 'high', 43 'metabox_priority' => 'side', 44 ), 45 ); 46 47 $this->assertEquals( $expected, $l['screens'] ); 48 } 49 50 public function test_setup_screens_use_global_fallbacks() { 51 $class_name = 'BPTest_Group_Extension_Setup_Screens_Use_Global_Fallbacks'; 52 $e = new $class_name(); 53 $e->_setup_class_info(); 54 $screens = $e->_get_default_screens(); 55 56 $fallback = array( 57 'screen_callback' => array( $e, 'settings_screen' ), 58 'screen_save_callback' => array( $e, 'settings_screen_save' ), 59 ); 60 $fallbacks = array( 61 'create' => $fallback, 62 'edit' => $fallback, 63 'admin' => $fallback, 64 ); 65 66 // strip everything from the screens array but what we we're 67 // testing 68 foreach ( $screens as &$screen ) { 69 foreach ( $screen as $k => $v ) { 70 if ( ! in_array( $k, array( 'screen_callback', 'screen_save_callback' ) ) ) { 71 unset( $screen[ $k ] ); 72 } 73 } 74 } 75 76 $this->assertEquals( $fallbacks, $screens ); 77 } 78 79 public function test_setup_screens_define_edit_screens_locally() { 80 $class_name = 'BPTest_Group_Extension_Setup_Screens_Define_Edit_Screens_Locally'; 81 $e = new $class_name(); 82 $e->_setup_class_info(); 83 $screens = $e->_get_default_screens(); 84 85 $fallback = array( 86 'screen_callback' => array( $e, 'settings_screen' ), 87 'screen_save_callback' => array( $e, 'settings_screen_save' ), 88 ); 89 $expected = array( 90 'create' => $fallback, 91 'edit' => array( 92 'screen_callback' => array( $e, 'edit_screen' ), 93 'screen_save_callback' => array( $e, 'edit_screen_save' ), 94 ), 95 'admin' => $fallback, 96 ); 97 98 // strip everything from the screens array but what we we're 99 // testing 100 foreach ( $screens as &$screen ) { 101 foreach ( $screen as $k => $v ) { 102 if ( ! in_array( $k, array( 'screen_callback', 'screen_save_callback' ) ) ) { 103 unset( $screen[ $k ] ); 104 } 105 } 106 } 107 108 $this->assertEquals( $screens, $expected ); 109 } 110 111 public function test_parse_args_r() { 112 $a = array( 113 'veggies' => 'yes', 114 'ice_cream' => 'dope', 115 'fruit' => array( 116 'apple' => 'gross', 117 'berries' => array( 118 'blueberries' => array( 119 'in_season' => 'never', 120 'oh' => 'boy', 121 ), 122 'cherries' => 'sometimes', 123 ), 124 ), 125 ); 126 127 $b = array( 128 'veggies' => 'no', 129 'cheese' => array( 130 'cheddar' => 'good', 131 ), 132 'fruit' => array( 133 'apple' => 'yum', 134 'berries' => array( 135 'strawberries' => 'awesome', 136 'blueberries' => array( 137 'in_season' => 'yes', 138 'out_of_season' => 'no', 139 ), 140 ), 141 ), 142 ); 143 144 $expected = array( 145 'veggies' => 'yes', 146 'ice_cream' => 'dope', 147 'cheese' => array( 148 'cheddar' => 'good', 149 ), 150 'fruit' => array( 151 'apple' => 'gross', 152 'berries' => array( 153 'strawberries' => 'awesome', 154 'blueberries' => array( 155 'in_season' => 'never', 156 'out_of_season' => 'no', 157 'oh' => 'boy', 158 ), 159 'cherries' => 'sometimes', 160 ), 161 ), 162 ); 163 164 $this->assertEquals( $expected, BP_Group_Extension::parse_args_r( $a, $b ) ); 165 } 166 167 /** 168 * Config that gets intentionally stored as a direct property of object 169 */ 170 public function test_access_root_property() { 171 $class_name = 'BPTest_Group_Extension_Access_Root_Property'; 172 $e = new $class_name(); 173 $e->_register(); 174 175 $this->assertEquals( 39, $e->nav_item_position ); 176 } 177 178 /** 179 * Config that gets registered using init(), but is then accessed via 180 * the legacy location 181 */ 182 public function test_access_init_property_using_legacy_location() { 183 $class_name = 'BPTest_Group_Extension_Access_Init_Property_Using_Legacy_Location'; 184 $e = new $class_name(); 185 $e->_register(); 186 187 $this->assertEquals( 18, $e->create_step_position ); 188 } 189 190 /** 191 * Provides settings_screen* and edit_screen* 192 */ 193 public function test_get_screen_callback_fallbacks() { 194 $class_name = 'BPTest_Group_Extension_Get_Screen_Callback_Fallbacks'; 195 $e = new $class_name(); 196 $e->_register(); 197 198 $this->assertEquals( array( $e, 'settings_screen' ), $e->screens['create']['screen_callback'] ); 199 $this->assertEquals( array( $e, 'settings_screen_save' ), $e->screens['create']['screen_save_callback'] ); 200 $this->assertEquals( array( $e, 'settings_screen' ), $e->screens['admin']['screen_callback'] ); 201 $this->assertEquals( array( $e, 'settings_screen_save' ), $e->screens['admin']['screen_save_callback'] ); 202 $this->assertEquals( array( $e, 'edit_screen' ), $e->screens['edit']['screen_callback'] ); 203 $this->assertEquals( array( $e, 'edit_screen_save' ), $e->screens['edit']['screen_save_callback'] ); 204 } 205 206 public function test_has_submit_button() { 207 $a = '<p>Foo bar</p><input type="text" name="awesome" /><input name="save" type="submit" id="saverrrr" />sweet'; 208 $this->assertTrue( BP_Group_Extension::has_submit_button( $a ) ); 209 210 $b = '<p>Foo bar</p><input type="text" name="awesome" />sweet'; 211 $this->assertFalse( BP_Group_Extension::has_submit_button( $b ) ); 212 213 // switch the quotation marks 214 $c = "<p>Foo bar</p><input type='text' name='awesome' /><input name='save' type='submit' id='saverrrr' />sweet"; 215 $this->assertTrue( BP_Group_Extension::has_submit_button( $c ) ); 216 } 217 218 /** 219 * @group enable_nav_item 220 * @expectedIncorrectUsage bp_nav 221 */ 222 public function test_enable_nav_item_true() { 223 $old_options_nav = buddypress()->bp_options_nav; 224 225 $g = self::factory()->group->create(); 226 $g_obj = groups_get_group( $g ); 227 228 $class_name = 'BPTest_Group_Extension_Enable_Nav_Item_True'; 229 $e = new $class_name(); 230 231 $this->go_to( bp_get_group_permalink( $g_obj ) ); 232 233 $e->_register(); 234 235 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 236 237 // Clean up 238 buddypress()->bp_options_nav = $old_options_nav; 239 } 240 241 /** 242 * @group enable_nav_item 243 * @expectedIncorrectUsage bp_nav 244 */ 245 public function test_enable_nav_item_false() { 246 $old_options_nav = buddypress()->bp_options_nav; 247 248 $g = self::factory()->group->create(); 249 $g_obj = groups_get_group( $g ); 250 251 $class_name = 'BPTest_Group_Extension_Enable_Nav_Item_False'; 252 $e = new $class_name(); 253 254 $this->go_to( bp_get_group_permalink( $g_obj ) ); 255 256 $e->_register(); 257 258 $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 259 260 // Clean up 261 buddypress()->bp_options_nav = $old_options_nav; 262 } 263 264 /** 265 * @group visibility 266 * @expectedIncorrectUsage bp_nav 267 */ 268 public function test_visibility_private() { 269 $old_options_nav = buddypress()->bp_options_nav; 270 $old_current_user = get_current_user_id(); 271 272 $g = self::factory()->group->create( array( 273 'status' => 'private', 274 ) ); 275 $g_obj = groups_get_group( $g ); 276 277 $class_name = 'BPTest_Group_Extension_Visibility_Private'; 278 $e = new $class_name(); 279 280 // Test as non-logged-in user 281 $this->set_current_user( 0 ); 282 $this->go_to( bp_get_group_permalink( $g_obj ) ); 283 $e->_register(); 284 $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 285 286 // Clean up 287 buddypress()->bp_options_nav = $old_options_nav; 288 289 // Test as group member 290 $u = self::factory()->user->create(); 291 $this->set_current_user( $u ); 292 $this->add_user_to_group( $u, $g ); 293 $this->go_to( bp_get_group_permalink( $g_obj ) ); 294 $e->_register(); 295 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 296 297 // Clean up 298 buddypress()->bp_options_nav = $old_options_nav; 299 $this->set_current_user( $old_current_user ); 300 } 301 302 /** 303 * @group visibility 304 * @expectedIncorrectUsage bp_nav 305 * 306 * visibility=public + status=private results in adding the item to 307 * the nav. However, BP_Groups_Component::setup_globals() bounces the 308 * user away from this page on a regular pageload (BP 2.0 and under) 309 * 310 * @see https://buddypress.trac.wordpress.org/ticket/4785 311 */ 312 public function test_visibility_public() { 313 $old_options_nav = buddypress()->bp_options_nav; 314 $old_current_user = get_current_user_id(); 315 316 $g = self::factory()->group->create( array( 317 'status' => 'private', 318 ) ); 319 $g_obj = groups_get_group( $g ); 320 321 $class_name = 'BPTest_Group_Extension_Visibility_Public'; 322 $e = new $class_name(); 323 324 // Test as non-logged-in user 325 $this->set_current_user( 0 ); 326 $this->go_to( bp_get_group_permalink( $g_obj ) ); 327 $e->_register(); 328 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 329 330 // Clean up 331 buddypress()->bp_options_nav = $old_options_nav; 332 333 // Test as group member 334 $u = self::factory()->user->create(); 335 $this->set_current_user( $u ); 336 $this->add_user_to_group( $u, $g ); 337 $this->go_to( bp_get_group_permalink( $g_obj ) ); 338 $e->_register(); 339 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 340 341 // Clean up 342 buddypress()->bp_options_nav = $old_options_nav; 343 $this->set_current_user( $old_current_user ); 344 } 345 346 /** 347 * @group user_can_visit 348 */ 349 public function test_user_can_visit_inferred_from_enable_nav_item() { 350 $old_current_user = get_current_user_id(); 351 352 $g = self::factory()->group->create( array( 353 'status' => 'public', 354 ) ); 355 $g_obj = groups_get_group( $g ); 356 $this->go_to( bp_get_group_permalink( $g_obj ) ); 357 358 $this->set_current_user( 0 ); 359 360 $e = new BPTest_Group_Extension_Inferred_Access_Settings_EnableNavItem_True(); 361 $e->_register(); 362 $this->assertTrue( $e->user_can_visit() ); 363 364 $e2 = new BPTest_Group_Extension_Inferred_Access_Settings_EnableNavItem_False(); 365 $e2->_register(); 366 $this->assertFalse( $e2->user_can_visit() ); 367 368 $this->set_current_user( $old_current_user ); 369 } 370 371 /** 372 * @group user_can_visit 373 */ 374 public function test_user_can_visit_explicit_for_logged_out_user() { 375 $old_current_user = get_current_user_id(); 376 $this->set_current_user( 0 ); 377 378 $g = self::factory()->group->create( array( 379 'status' => 'public', 380 ) ); 381 $g_obj = groups_get_group( $g ); 382 $this->go_to( bp_get_group_permalink( $g_obj ) ); 383 384 $e1 = new BPTest_Group_Extension_Access_Anyone(); 385 $e1->_register(); 386 $this->assertTrue( $e1->user_can_visit() ); 387 388 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 389 $e2->_register(); 390 $this->assertFalse( $e2->user_can_visit() ); 391 392 $e3 = new BPTest_Group_Extension_Access_Member(); 393 $e3->_register(); 394 $this->assertFalse( $e3->user_can_visit() ); 395 396 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 397 $e4->_register(); 398 $this->assertFalse( $e4->user_can_visit() ); 399 400 $e5 = new BPTest_Group_Extension_Access_Admin(); 401 $e5->_register(); 402 $this->assertFalse( $e5->user_can_visit() ); 403 404 $e6 = new BPTest_Group_Extension_Access_Noone(); 405 $e6->_register(); 406 $this->assertFalse( $e6->user_can_visit() ); 407 408 $this->set_current_user( $old_current_user ); 409 } 410 411 /** 412 * @group user_can_visit 413 */ 414 public function test_user_can_visit_explicit_for_logged_in_user() { 415 $g = self::factory()->group->create( array( 416 'status' => 'public', 417 ) ); 418 $g_obj = groups_get_group( $g ); 419 420 $u = self::factory()->user->create(); 421 $old_current_user = get_current_user_id(); 422 $this->set_current_user( $u ); 423 424 $this->go_to( bp_get_group_permalink( $g_obj ) ); 425 426 $e1 = new BPTest_Group_Extension_Access_Anyone(); 427 $e1->_register(); 428 $this->assertTrue( $e1->user_can_visit() ); 429 430 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 431 $e2->_register(); 432 $this->assertTrue( $e2->user_can_visit() ); 433 434 $e3 = new BPTest_Group_Extension_Access_Member(); 435 $e3->_register(); 436 $this->assertFalse( $e3->user_can_visit() ); 437 438 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 439 $e4->_register(); 440 $this->assertFalse( $e4->user_can_visit() ); 441 442 $e5 = new BPTest_Group_Extension_Access_Admin(); 443 $e5->_register(); 444 $this->assertFalse( $e5->user_can_visit() ); 445 446 $e6 = new BPTest_Group_Extension_Access_Noone(); 447 $e6->_register(); 448 $this->assertFalse( $e6->user_can_visit() ); 449 450 $this->set_current_user( $old_current_user ); 451 } 452 453 /** 454 * @group user_can_visit 455 */ 456 public function test_user_can_visit_explicit_for_group_member() { 457 $g = self::factory()->group->create( array( 458 'status' => 'public', 459 ) ); 460 $g_obj = groups_get_group( $g ); 461 462 $u = self::factory()->user->create(); 463 $old_current_user = get_current_user_id(); 464 $this->set_current_user( $u ); 465 466 $this->add_user_to_group( $u, $g ); 467 468 $this->go_to( bp_get_group_permalink( $g_obj ) ); 469 470 $e1 = new BPTest_Group_Extension_Access_Anyone(); 471 $e1->_register(); 472 $this->assertTrue( $e1->user_can_visit() ); 473 474 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 475 $e2->_register(); 476 $this->assertTrue( $e2->user_can_visit() ); 477 478 $e3 = new BPTest_Group_Extension_Access_Member(); 479 $e3->_register(); 480 $this->assertTrue( $e3->user_can_visit() ); 481 482 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 483 $e4->_register(); 484 $this->assertFalse( $e4->user_can_visit() ); 485 486 $e5 = new BPTest_Group_Extension_Access_Admin(); 487 $e5->_register(); 488 $this->assertFalse( $e5->user_can_visit() ); 489 490 $e6 = new BPTest_Group_Extension_Access_Noone(); 491 $e6->_register(); 492 $this->assertFalse( $e6->user_can_visit() ); 493 494 $this->set_current_user( $old_current_user ); 495 } 496 497 /** 498 * @group user_can_visit 499 */ 500 public function test_user_can_visit_explicit_for_group_mod() { 501 $g = self::factory()->group->create( array( 502 'status' => 'public', 503 ) ); 504 $g_obj = groups_get_group( $g ); 505 506 $u = self::factory()->user->create(); 507 $old_current_user = get_current_user_id(); 508 $this->set_current_user( $u ); 509 510 $m = $this->add_user_to_group( $u, $g ); 511 $gm = new BP_Groups_Member( $u, $g ); 512 $gm->promote( 'mod' ); 513 514 $this->go_to( bp_get_group_permalink( $g_obj ) ); 515 516 $e1 = new BPTest_Group_Extension_Access_Anyone(); 517 $e1->_register(); 518 $this->assertTrue( $e1->user_can_visit() ); 519 520 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 521 $e2->_register(); 522 $this->assertTrue( $e2->user_can_visit() ); 523 524 $e3 = new BPTest_Group_Extension_Access_Member(); 525 $e3->_register(); 526 $this->assertTrue( $e3->user_can_visit() ); 527 528 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 529 $e4->_register(); 530 $this->assertTrue( $e4->user_can_visit() ); 531 532 $e5 = new BPTest_Group_Extension_Access_Admin(); 533 $e5->_register(); 534 $this->assertFalse( $e5->user_can_visit() ); 535 536 $e6 = new BPTest_Group_Extension_Access_Noone(); 537 $e6->_register(); 538 $this->assertFalse( $e6->user_can_visit() ); 539 540 $this->set_current_user( $old_current_user ); 541 } 542 543 /** 544 * @group user_can_visit 545 */ 546 public function test_user_can_visit_explicit_for_group_admin() { 547 $g = self::factory()->group->create( array( 548 'status' => 'public', 549 ) ); 550 $g_obj = groups_get_group( $g ); 551 552 $u = self::factory()->user->create(); 553 $old_current_user = get_current_user_id(); 554 $this->set_current_user( $u ); 555 556 $m = $this->add_user_to_group( $u, $g ); 557 $gm = new BP_Groups_Member( $u, $g ); 558 $gm->promote( 'admin' ); 559 560 $this->go_to( bp_get_group_permalink( $g_obj ) ); 561 562 $e1 = new BPTest_Group_Extension_Access_Anyone(); 563 $e1->_register(); 564 $this->assertTrue( $e1->user_can_visit() ); 565 566 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 567 $e2->_register(); 568 $this->assertTrue( $e2->user_can_visit() ); 569 570 $e3 = new BPTest_Group_Extension_Access_Member(); 571 $e3->_register(); 572 $this->assertTrue( $e3->user_can_visit() ); 573 574 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 575 $e4->_register(); 576 $this->assertTrue( $e4->user_can_visit() ); 577 578 $e5 = new BPTest_Group_Extension_Access_Admin(); 579 $e5->_register(); 580 $this->assertTrue( $e5->user_can_visit() ); 581 582 $e6 = new BPTest_Group_Extension_Access_Noone(); 583 $e6->_register(); 584 $this->assertFalse( $e6->user_can_visit() ); 585 586 $this->set_current_user( $old_current_user ); 587 } 588 589 /** 590 * @group user_can_see_nav_item 591 */ 592 public function test_user_can_see_nav_item_implied() { 593 $g = self::factory()->group->create( array( 594 'status' => 'public', 595 ) ); 596 $g_obj = groups_get_group( $g ); 597 598 $old_current_user = get_current_user_id(); 599 $this->set_current_user( 0 ); 600 601 $this->go_to( bp_get_group_permalink( $g_obj ) ); 602 603 $e1 = new BPTest_Group_Extension_Access_Anyone(); 604 $e1->_register(); 605 $this->assertTrue( $e1->user_can_see_nav_item() ); 606 607 $e2 = new BPTest_Group_Extension_Access_Loggedin(); 608 $e2->_register(); 609 $this->assertFalse( $e2->user_can_see_nav_item() ); 610 611 $e3 = new BPTest_Group_Extension_Access_Member(); 612 $e3->_register(); 613 $this->assertFalse( $e3->user_can_see_nav_item() ); 614 615 $e4 = new BPTest_Group_Extension_Access_AdminMod(); 616 $e4->_register(); 617 $this->assertFalse( $e4->user_can_see_nav_item() ); 618 619 $e5 = new BPTest_Group_Extension_Access_Admin(); 620 $e5->_register(); 621 $this->assertFalse( $e5->user_can_see_nav_item() ); 622 623 $e6 = new BPTest_Group_Extension_Access_Noone(); 624 $e6->_register(); 625 $this->assertFalse( $e6->user_can_visit() ); 626 627 $this->set_current_user( $old_current_user ); 628 } 629 630 /** 631 * @group user_can_see_nav_item 632 */ 633 public function test_user_can_see_nav_item_explicit_for_logged_out_user() { 634 $g = self::factory()->group->create( array( 635 'status' => 'public', 636 ) ); 637 $g_obj = groups_get_group( $g ); 638 639 $old_current_user = get_current_user_id(); 640 $this->set_current_user( 0 ); 641 642 $this->go_to( bp_get_group_permalink( $g_obj ) ); 643 644 $e1 = new BPTest_Group_Extension_ShowTab_Anyone(); 645 $e1->_register(); 646 $this->assertTrue( $e1->user_can_see_nav_item() ); 647 648 $e2 = new BPTest_Group_Extension_ShowTab_Loggedin(); 649 $e2->_register(); 650 $this->assertFalse( $e2->user_can_see_nav_item() ); 651 652 $e3 = new BPTest_Group_Extension_ShowTab_Member(); 653 $e3->_register(); 654 $this->assertFalse( $e3->user_can_see_nav_item() ); 655 656 $e4 = new BPTest_Group_Extension_ShowTab_AdminMod(); 657 $e4->_register(); 658 $this->assertFalse( $e4->user_can_see_nav_item() ); 659 660 $e5 = new BPTest_Group_Extension_ShowTab_Admin(); 661 $e5->_register(); 662 $this->assertFalse( $e5->user_can_see_nav_item() ); 663 664 $e6 = new BPTest_Group_Extension_ShowTab_Noone(); 665 $e6->_register(); 666 $this->assertFalse( $e6->user_can_see_nav_item() ); 667 668 $this->set_current_user( $old_current_user ); 669 } 670 671 /** 672 * @group user_can_see_nav_item 673 */ 674 public function test_user_can_see_nav_item_explicit_for_logged_in_user() { 675 $g = self::factory()->group->create( array( 676 'status' => 'public', 677 ) ); 678 $g_obj = groups_get_group( $g ); 679 680 $u = self::factory()->user->create(); 681 $old_current_user = get_current_user_id(); 682 $this->set_current_user( $u ); 683 684 $this->go_to( bp_get_group_permalink( $g_obj ) ); 685 686 $e1 = new BPTest_Group_Extension_ShowTab_Anyone(); 687 $e1->_register(); 688 $this->assertTrue( $e1->user_can_see_nav_item() ); 689 690 $e2 = new BPTest_Group_Extension_ShowTab_Loggedin(); 691 $e2->_register(); 692 $this->assertTrue( $e2->user_can_see_nav_item() ); 693 694 $e3 = new BPTest_Group_Extension_ShowTab_Member(); 695 $e3->_register(); 696 $this->assertFalse( $e3->user_can_see_nav_item() ); 697 698 $e4 = new BPTest_Group_Extension_ShowTab_AdminMod(); 699 $e4->_register(); 700 $this->assertFalse( $e4->user_can_see_nav_item() ); 701 702 $e5 = new BPTest_Group_Extension_ShowTab_Admin(); 703 $e5->_register(); 704 $this->assertFalse( $e5->user_can_see_nav_item() ); 705 706 $e6 = new BPTest_Group_Extension_ShowTab_Noone(); 707 $e6->_register(); 708 $this->assertFalse( $e6->user_can_see_nav_item() ); 709 710 $this->set_current_user( $old_current_user ); 711 } 712 713 /** 714 * @group user_can_see_nav_item 715 */ 716 public function test_user_can_see_nav_item_explicit_for_group_member() { 717 $g = self::factory()->group->create( array( 718 'status' => 'public', 719 ) ); 720 $g_obj = groups_get_group( $g ); 721 722 $u = self::factory()->user->create(); 723 $old_current_user = get_current_user_id(); 724 $this->set_current_user( $u ); 725 726 $this->add_user_to_group( $u, $g ); 727 728 $this->go_to( bp_get_group_permalink( $g_obj ) ); 729 730 $e1 = new BPTest_Group_Extension_ShowTab_Anyone(); 731 $e1->_register(); 732 $this->assertTrue( $e1->user_can_see_nav_item() ); 733 734 $e2 = new BPTest_Group_Extension_ShowTab_Loggedin(); 735 $e2->_register(); 736 $this->assertTrue( $e2->user_can_see_nav_item() ); 737 738 $e3 = new BPTest_Group_Extension_ShowTab_Member(); 739 $e3->_register(); 740 $this->assertTrue( $e3->user_can_see_nav_item() ); 741 742 $e4 = new BPTest_Group_Extension_ShowTab_AdminMod(); 743 $e4->_register(); 744 $this->assertFalse( $e4->user_can_see_nav_item() ); 745 746 $e5 = new BPTest_Group_Extension_ShowTab_Admin(); 747 $e5->_register(); 748 $this->assertFalse( $e5->user_can_see_nav_item() ); 749 750 $e6 = new BPTest_Group_Extension_ShowTab_Noone(); 751 $e6->_register(); 752 $this->assertFalse( $e6->user_can_see_nav_item() ); 753 754 $this->set_current_user( $old_current_user ); 755 } 756 757 /** 758 * @group user_can_see_nav_item 759 */ 760 public function test_user_can_see_nav_item_explicit_for_group_mod() { 761 $g = self::factory()->group->create( array( 762 'status' => 'public', 763 ) ); 764 $g_obj = groups_get_group( $g ); 765 766 $u = self::factory()->user->create(); 767 $old_current_user = get_current_user_id(); 768 $this->set_current_user( $u ); 769 770 $this->add_user_to_group( $u, $g ); 771 $gm = new BP_Groups_Member( $u, $g ); 772 $gm->promote( 'mod' ); 773 774 $this->go_to( bp_get_group_permalink( $g_obj ) ); 775 776 $e1 = new BPTest_Group_Extension_ShowTab_Anyone(); 777 $e1->_register(); 778 $this->assertTrue( $e1->user_can_see_nav_item() ); 779 780 $e2 = new BPTest_Group_Extension_ShowTab_Loggedin(); 781 $e2->_register(); 782 $this->assertTrue( $e2->user_can_see_nav_item() ); 783 784 $e3 = new BPTest_Group_Extension_ShowTab_Member(); 785 $e3->_register(); 786 $this->assertTrue( $e3->user_can_see_nav_item() ); 787 788 $e4 = new BPTest_Group_Extension_ShowTab_AdminMod(); 789 $e4->_register(); 790 $this->assertTrue( $e4->user_can_see_nav_item() ); 791 792 $e5 = new BPTest_Group_Extension_ShowTab_Admin(); 793 $e5->_register(); 794 $this->assertFalse( $e5->user_can_see_nav_item() ); 795 796 $e6 = new BPTest_Group_Extension_ShowTab_Noone(); 797 $e6->_register(); 798 $this->assertFalse( $e6->user_can_see_nav_item() ); 799 800 $this->set_current_user( $old_current_user ); 801 } 802 803 /** 804 * @group user_can_see_nav_item 805 */ 806 public function test_user_can_see_nav_item_explicit_for_group_admin() { 807 $g = self::factory()->group->create( array( 808 'status' => 'public', 809 ) ); 810 $g_obj = groups_get_group( $g ); 811 812 $u = self::factory()->user->create(); 813 $old_current_user = get_current_user_id(); 814 $this->set_current_user( $u ); 815 816 $this->add_user_to_group( $u, $g ); 817 $gm = new BP_Groups_Member( $u, $g ); 818 $gm->promote( 'admin' ); 819 820 $this->go_to( bp_get_group_permalink( $g_obj ) ); 821 822 $e1 = new BPTest_Group_Extension_ShowTab_Anyone(); 823 $e1->_register(); 824 $this->assertTrue( $e1->user_can_see_nav_item() ); 825 826 $e2 = new BPTest_Group_Extension_ShowTab_Loggedin(); 827 $e2->_register(); 828 $this->assertTrue( $e2->user_can_see_nav_item() ); 829 830 $e3 = new BPTest_Group_Extension_ShowTab_Member(); 831 $e3->_register(); 832 $this->assertTrue( $e3->user_can_see_nav_item() ); 833 834 $e4 = new BPTest_Group_Extension_ShowTab_AdminMod(); 835 $e4->_register(); 836 $this->assertTrue( $e4->user_can_see_nav_item() ); 837 838 $e5 = new BPTest_Group_Extension_ShowTab_Admin(); 839 $e5->_register(); 840 $this->assertTrue( $e5->user_can_see_nav_item() ); 841 842 $e6 = new BPTest_Group_Extension_ShowTab_Noone(); 843 $e6->_register(); 844 $this->assertFalse( $e6->user_can_see_nav_item() ); 845 846 $this->set_current_user( $old_current_user ); 847 } 848 849 /** 850 * @ticket BP7131 851 */ 852 public function test_widget_on_group_home_page() { 853 $g = self::factory()->group->create( array( 854 'status' => 'public', 855 ) ); 856 $g_obj = groups_get_group( $g ); 857 858 $this->go_to( bp_get_group_permalink( $g_obj ) ); 859 860 $e1 = new BPTest_Group_Extension_Widget_Method(); 861 $e1->_register(); 862 863 ob_start(); 864 bp_custom_group_boxes(); 865 $content = ob_get_clean(); 866 867 $this->assertTrue( $content === 'Widget Displayed' ); 868 } 869 870 /** 871 * @ticket BP7131 872 */ 873 public function test_widget_on_group_members_page() { 874 $g = self::factory()->group->create( array( 875 'status' => 'public', 876 ) ); 877 $g_obj = groups_get_group( $g ); 878 879 $this->go_to( trailingslashit( bp_get_group_permalink( $g_obj ) ) . 'members/' ); 880 881 $e1 = new BPTest_Group_Extension_Widget_Method(); 882 $e1->_register(); 883 884 ob_start(); 885 bp_custom_group_boxes(); 886 $content = ob_get_clean(); 887 888 $this->assertFalse( $content === 'Widget Displayed' ); 889 } 890 891 /** 892 * @ticket BP8558 893 */ 894 public function test_adding_multiple_extension_classes() { 895 $old_options_nav = buddypress()->bp_options_nav; 896 897 $g = self::factory()->group->create(); 898 $g_obj = groups_get_group( $g ); 899 900 $e = new BPTest_Group_Extension_Enable_Nav_Item_True(); 901 $e_slug = 'bptest_group_extension_enable_nav_item_true'; 902 $e_class_name = get_class( $e ); 903 $f = new BPTest_Group_Extension_Access_Anyone(); 904 $f_slug = 'bptest_group_extension_access_anyone'; 905 $f_class_name = get_class( $f ); 906 907 bp_register_group_extension( $e_class_name ); 908 bp_register_group_extension( $f_class_name ); 909 910 $this->go_to( bp_get_group_permalink( $g_obj ) ); 911 $nav = buddypress()->groups->nav->get_secondary( array( 912 'parent_slug' => $g_obj->slug , 913 ) ); 914 915 $slugs = array(); 916 foreach ( $nav as $priority => $nav_obj ) { 917 $slugs[] = $nav_obj->slug; 918 } 919 920 $this->assertTrue( in_array( $e_slug, $slugs, true ) && in_array( $f_slug, $slugs, true ) ); 921 922 // Clean up 923 buddypress()->bp_options_nav = $old_options_nav; 924 } 925 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |