Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/06/2015 12:39:46 AM (9 years ago)
Author:
dcavins
Message:

Allow access-protected bp_nav items to exist.

Fix error introduced in r10003 that prevents
access-protected nav items from being added to the
bp_nav array. The access protection should
happen at access time in
bp_core_register_nav_screen_function().

See #6503.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/nav/bpCoreNewNavItem.php

    r9990 r10326  
    125125    }
    126126
     127    public function test_existence_of_access_protected_user_nav() {
     128        $bp_nav = buddypress()->bp_nav;
     129
     130        $u = $this->factory->user->create();
     131        $u2 = $this->factory->user->create();
     132        $old_current_user = get_current_user_id();
     133        $this->set_current_user( $u2 );
     134
     135        $this->go_to( bp_core_get_user_domain( $u ) );
     136
     137        $expected = array(
     138            'name'                    => 'Settings',
     139            'slug'                    => 'settings',
     140            'link'                    => trailingslashit( bp_loggedin_user_domain() . 'settings' ),
     141            'css_id'                  => 'settings',
     142            'show_for_displayed_user' => false,
     143            'position'                => 100,
     144            'screen_function'         => 'bp_settings_screen_general',
     145            'default_subnav_slug'     => 'general'
     146        );
     147
     148        $this->assertSame( buddypress()->bp_nav['settings'], $expected );
     149
     150        // Clean up
     151        buddypress()->bp_nav = $bp_nav;
     152        $this->set_current_user( $old_current_user );
     153    }
     154
     155    public function test_creation_of_access_protected_user_nav() {
     156        // The nav item must be added to bp_nav, even if the current user
     157        // can't visit that nav item.
     158        $bp_nav = buddypress()->bp_nav;
     159
     160        $u = $this->factory->user->create();
     161        $u2 = $this->factory->user->create();
     162        $old_current_user = get_current_user_id();
     163        $this->set_current_user( $u2 );
     164
     165        $this->go_to( bp_core_get_user_domain( $u ) );
     166
     167        bp_core_new_nav_item( array(
     168            'name'                    => 'Woof',
     169            'slug'                    => 'woof',
     170            'show_for_displayed_user' => false,
     171            'position'                => 35,
     172            'screen_function'         => 'woof_screen_function',
     173            'default_subnav_slug'     => 'woof-one'
     174        ) );
     175
     176        $expected = array(
     177            'name'                    => 'Woof',
     178            'slug'                    => 'woof',
     179            'link'                    => trailingslashit( bp_loggedin_user_domain() . 'woof' ),
     180            'css_id'                  => 'woof',
     181            'show_for_displayed_user' => false,
     182            'position'                => 35,
     183            'screen_function'         => 'woof_screen_function',
     184            'default_subnav_slug'     => 'woof-one'
     185        );
     186
     187        $this->assertSame( buddypress()->bp_nav['woof'], $expected );
     188
     189        // Clean up
     190        buddypress()->bp_nav = $bp_nav;
     191        $this->set_current_user( $old_current_user );
     192    }
    127193}
Note: See TracChangeset for help on using the changeset viewer.