Skip to:
Content

BuddyPress.org

Changeset 8545


Ignore:
Timestamp:
06/22/2014 06:53:38 PM (11 years ago)
Author:
boonebgorges
Message:

Add unit tests for bp_core_maybe_hook_new_subnav_screen_function()

See #5720

File:
1 edited

Legend:

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

    r8540 r8545  
    137137        buddypress()->bp_options_nav = $bp_options_nav;
    138138    }
     139
     140    /**
     141     * @group bp_core_maybe_hook_new_subnav_screen_function
     142     */
     143    public function test_maybe_hook_new_subnav_screen_function_user_has_access_true_no_callable_function() {
     144        $subnav_item = array(
     145            'user_has_access' => true,
     146            'screen_function' => '123foo456',
     147        );
     148
     149        $expected = array(
     150            'status' => 'failure',
     151        );
     152
     153        $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );
     154    }
     155
     156    /**
     157     * @group bp_core_maybe_hook_new_subnav_screen_function
     158     */
     159    public function test_maybe_hook_new_subnav_screen_function_user_has_access_true_callable_function() {
     160        $subnav_item = array(
     161            'user_has_access' => true,
     162            'screen_function' => 'wptexturize', // any old callable function
     163        );
     164
     165        $expected = array(
     166            'status' => 'success',
     167        );
     168
     169        $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );
     170
     171        // clean up
     172        remove_action( 'bp_screens', 'wptexturize', 3 );
     173    }
     174
     175    /**
     176     * @group bp_core_maybe_hook_new_subnav_screen_function
     177     */
     178    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_out() {
     179        $old_current_user = get_current_user_id();
     180        $this->set_current_user( 0 );
     181
     182        $subnav_item = array(
     183            'user_has_access' => false,
     184        );
     185
     186        $expected = array(
     187            'status' => 'failure',
     188            'redirect_args' => array(),
     189        );
     190
     191        $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );
     192
     193        $this->set_current_user( $old_current_user );
     194    }
     195
     196    /**
     197     * @group bp_core_maybe_hook_new_subnav_screen_function
     198     */
     199    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_my_profile() {
     200        $u = $this->create_user();
     201        $old_current_user = get_current_user_id();
     202        $this->set_current_user( $u );
     203
     204        $this->go_to( bp_core_get_user_domain( $u ) );
     205
     206        $subnav_item = array(
     207            'user_has_access' => false,
     208        );
     209
     210        // Just test relevant info
     211        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     212        $this->assertSame( 'failure', $found['status'] );
     213        $this->assertSame( bp_core_get_user_domain( $u ), $found['redirect_args']['root'] );
     214
     215        $this->set_current_user( $old_current_user );
     216    }
     217
     218    /**
     219     * @group bp_core_maybe_hook_new_subnav_screen_function
     220     */
     221    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_others_profile_default_component_accessible() {
     222        $u1 = $this->create_user();
     223        $u2 = $this->create_user();
     224        $old_current_user = get_current_user_id();
     225        $this->set_current_user( $u1 );
     226
     227        $this->go_to( bp_core_get_user_domain( $u2 ) );
     228
     229        $old_bp_nav = buddypress()->bp_nav;
     230        $old_default_component = buddypress()->default_component;
     231        buddypress()->default_component = 'foo';
     232        buddypress()->bp_nav = array(
     233            'foo' => array(
     234                'show_for_displayed_user' => true,
     235            ),
     236        );
     237
     238        $subnav_item = array(
     239            'user_has_access' => false,
     240        );
     241
     242        // Just test relevant info
     243        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     244        $this->assertSame( 'failure', $found['status'] );
     245        $this->assertSame( bp_core_get_user_domain( $u2 ), $found['redirect_args']['root'] );
     246
     247        // Clean up
     248        $this->set_current_user( $old_current_user );
     249        buddypress()->default_component = $old_default_component;
     250        buddypress()->bp_nav = $old_bp_nav;
     251    }
     252
     253    /**
     254     * @group bp_core_maybe_hook_new_subnav_screen_function
     255     */
     256    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_others_profile_default_component_not_accessible() {
     257        $u1 = $this->create_user();
     258        $u2 = $this->create_user();
     259        $old_current_user = get_current_user_id();
     260        $this->set_current_user( $u1 );
     261
     262        $this->go_to( bp_core_get_user_domain( $u2 ) );
     263
     264        $old_bp_nav = buddypress()->bp_nav;
     265        $old_default_component = buddypress()->default_component;
     266        buddypress()->default_component = 'foo';
     267        buddypress()->bp_nav = array(
     268            'foo' => array(
     269                'show_for_displayed_user' => false,
     270            ),
     271        );
     272
     273        $subnav_item = array(
     274            'user_has_access' => false,
     275        );
     276
     277        // Just test relevant info
     278        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     279        $this->assertSame( 'failure', $found['status'] );
     280        $this->assertSame( bp_core_get_user_domain( $u2 ) . bp_get_activity_slug() . '/', $found['redirect_args']['root'] );
     281
     282        // Clean up
     283        $this->set_current_user( $old_current_user );
     284        buddypress()->default_component = $old_default_component;
     285        buddypress()->bp_nav = $old_bp_nav;
     286    }
    139287}
Note: See TracChangeset for help on using the changeset viewer.