Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/25/2023 05:18:41 PM (11 months ago)
Author:
imath
Message:

Fully deprecate bp_nav & bp_options_nav BP globals

These back compatibility mechanism, which was in BP since version 2.6, has moved to the BP Classic plugin.

Fixes #8927
Closes https://github.com/buddypress/buddypress/pull/121

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-group-extension.php

    r13441 r13507  
    229229
    230230    /**
    231      * @group enable_nav_item
    232      * @expectedIncorrectUsage bp_nav
    233      */
    234     public function test_enable_nav_item_true() {
    235         $old_options_nav = buddypress()->bp_options_nav;
    236         $this->set_permalink_structure( '/%postname%/' );
    237 
    238         $g = self::factory()->group->create();
    239         $g_obj = groups_get_group( $g );
    240 
    241         $class_name = 'BPTest_Group_Extension_Enable_Nav_Item_True';
    242         $e = new $class_name();
    243 
    244         $this->go_to( bp_get_group_url( $g_obj ) );
    245 
    246         $e->_register();
    247 
    248         $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    249 
    250         // Clean up
    251         buddypress()->bp_options_nav = $old_options_nav;
    252     }
    253 
    254     /**
    255      * @group enable_nav_item
    256      * @expectedIncorrectUsage bp_nav
    257      */
    258     public function test_enable_nav_item_false() {
    259         $this->set_permalink_structure( '/%postname%/' );
    260         $old_options_nav = buddypress()->bp_options_nav;
    261 
    262         $g = self::factory()->group->create();
    263         $g_obj = groups_get_group( $g );
    264 
    265         $class_name = 'BPTest_Group_Extension_Enable_Nav_Item_False';
    266         $e = new $class_name();
    267 
    268         $this->go_to( bp_get_group_url( $g_obj ) );
    269 
    270         $e->_register();
    271 
    272         $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    273 
    274         // Clean up
    275         buddypress()->bp_options_nav = $old_options_nav;
    276     }
    277 
    278     /**
    279      * @group visibility
    280      * @expectedIncorrectUsage bp_nav
    281      */
    282     public function test_visibility_private() {
    283         $this->set_permalink_structure( '/%postname%/' );
    284         $old_options_nav = buddypress()->bp_options_nav;
    285         $old_current_user = get_current_user_id();
    286 
    287         $g = self::factory()->group->create( array(
    288             'status' => 'private',
    289         ) );
    290         $g_obj = groups_get_group( $g );
    291 
    292         $class_name = 'BPTest_Group_Extension_Visibility_Private';
    293         $e = new $class_name();
    294 
    295         // Test as non-logged-in user
    296         $this->set_current_user( 0 );
    297         $this->go_to( bp_get_group_url( $g_obj ) );
    298         $e->_register();
    299         $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    300 
    301         // Clean up
    302         buddypress()->bp_options_nav = $old_options_nav;
    303 
    304         // Test as group member
    305         $u = self::factory()->user->create();
    306         $this->set_current_user( $u );
    307         $this->add_user_to_group( $u, $g );
    308         $this->go_to( bp_get_group_url( $g_obj ) );
    309         $e->_register();
    310         $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    311 
    312         // Clean up
    313         buddypress()->bp_options_nav = $old_options_nav;
    314         $this->set_current_user( $old_current_user );
    315     }
    316 
    317     /**
    318      * @group visibility
    319      * @expectedIncorrectUsage bp_nav
    320      *
    321      * visibility=public + status=private results in adding the item to
    322      * the nav. However, BP_Groups_Component::setup_globals() bounces the
    323      * user away from this page on a regular pageload (BP 2.0 and under)
    324      *
    325      * @see https://buddypress.trac.wordpress.org/ticket/4785
    326      */
    327     public function test_visibility_public() {
    328         $this->set_permalink_structure( '/%postname%/' );
    329         $old_options_nav = buddypress()->bp_options_nav;
    330         $old_current_user = get_current_user_id();
    331 
    332         $g = self::factory()->group->create( array(
    333             'status' => 'private',
    334         ) );
    335         $g_obj = groups_get_group( $g );
    336 
    337         $class_name = 'BPTest_Group_Extension_Visibility_Public';
    338         $e = new $class_name();
    339 
    340         // Test as non-logged-in user
    341         $this->set_current_user( 0 );
    342         $this->go_to( bp_get_group_url( $g_obj ) );
    343         $e->_register();
    344         $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    345 
    346         // Clean up
    347         buddypress()->bp_options_nav = $old_options_nav;
    348 
    349         // Test as group member
    350         $u = self::factory()->user->create();
    351         $this->set_current_user( $u );
    352         $this->add_user_to_group( $u, $g );
    353         $this->go_to( bp_get_group_url( $g_obj ) );
    354         $e->_register();
    355         $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );
    356 
    357         // Clean up
    358         buddypress()->bp_options_nav = $old_options_nav;
    359         $this->set_current_user( $old_current_user );
    360     }
    361 
    362     /**
    363231     * @group user_can_visit
    364232     */
Note: See TracChangeset for help on using the changeset viewer.