[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group core 4 * @group nav 5 */ 6 class BP_Tests_Core_Nav_BpCoreMaybeHookNewSubnavScreenFunction extends BP_UnitTestCase { 7 8 public function test_user_has_access_true_no_callable_function() { 9 $subnav_item = array( 10 'user_has_access' => true, 11 'screen_function' => '123foo456', 12 ); 13 14 $expected = array( 15 'status' => 'failure', 16 ); 17 18 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) ); 19 } 20 21 public function test_user_has_access_true_callable_function() { 22 $subnav_item = array( 23 'user_has_access' => true, 24 'screen_function' => 'wptexturize', // any old callable function 25 ); 26 27 $expected = array( 28 'status' => 'success', 29 ); 30 31 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) ); 32 33 // clean up 34 remove_action( 'bp_screens', 'wptexturize', 3 ); 35 } 36 37 public function test_user_has_access_false_user_logged_out() { 38 $old_current_user = get_current_user_id(); 39 $this->set_current_user( 0 ); 40 41 $subnav_item = array( 42 'user_has_access' => false, 43 ); 44 45 $expected = array( 46 'status' => 'failure', 47 'redirect_args' => array(), 48 ); 49 50 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) ); 51 52 $this->set_current_user( $old_current_user ); 53 } 54 55 public function test_user_has_access_false_user_logged_in_my_profile() { 56 $u = self::factory()->user->create(); 57 $old_current_user = get_current_user_id(); 58 $this->set_current_user( $u ); 59 60 $this->go_to( bp_core_get_user_domain( $u ) ); 61 62 $subnav_item = array( 63 'user_has_access' => false, 64 ); 65 66 // Just test relevant info 67 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 68 $this->assertSame( 'failure', $found['status'] ); 69 $this->assertSame( bp_core_get_user_domain( $u ), $found['redirect_args']['root'] ); 70 71 $this->set_current_user( $old_current_user ); 72 } 73 74 public function test_user_has_access_false_user_logged_in_others_profile_default_component_accessible() { 75 $u1 = self::factory()->user->create(); 76 $u2 = self::factory()->user->create(); 77 $old_current_user = get_current_user_id(); 78 $this->set_current_user( $u1 ); 79 80 $this->go_to( bp_core_get_user_domain( $u2 ) ); 81 82 $old_bp_nav = buddypress()->bp_nav; 83 $old_default_component = buddypress()->default_component; 84 buddypress()->default_component = 'foo'; 85 86 bp_core_new_nav_item( array( 87 'slug' => 'foo', 88 'name' => 'Foo', 89 'screen_function' => 'foo', 90 'default_subnav_item' => 'bar', 91 ) ); 92 93 $subnav_item = array( 94 'user_has_access' => false, 95 ); 96 97 // Just test relevant info 98 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 99 100 // Clean up 101 $this->set_current_user( $old_current_user ); 102 buddypress()->default_component = $old_default_component; 103 buddypress()->bp_nav = $old_bp_nav; 104 105 $this->assertSame( 'failure', $found['status'] ); 106 $this->assertSame( bp_core_get_user_domain( $u2 ), $found['redirect_args']['root'] ); 107 } 108 109 public function test_user_has_access_false_user_logged_in_others_profile_default_component_not_accessible() { 110 $u1 = self::factory()->user->create(); 111 $u2 = self::factory()->user->create(); 112 $old_current_user = get_current_user_id(); 113 $this->set_current_user( $u1 ); 114 115 $this->go_to( bp_core_get_user_domain( $u2 ) ); 116 117 $old_bp_nav = buddypress()->bp_nav; 118 $old_default_component = buddypress()->default_component; 119 buddypress()->default_component = 'foo'; 120 121 bp_core_new_nav_item( array( 122 'slug' => 'foo', 123 'name' => 'Foo', 124 'screen_function' => 'foo', 125 'default_subnav_item' => 'bar', 126 'show_for_displayed_user' => false, 127 ) ); 128 129 $subnav_item = array( 130 'user_has_access' => false, 131 ); 132 133 // Just test relevant info 134 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 135 136 // Clean up 137 $this->set_current_user( $old_current_user ); 138 buddypress()->default_component = $old_default_component; 139 buddypress()->bp_nav = $old_bp_nav; 140 141 $this->assertSame( 'failure', $found['status'] ); 142 $this->assertSame( bp_core_get_user_domain( $u2 ) . bp_get_activity_slug() . '/', $found['redirect_args']['root'] ); 143 } 144 145 public function test_user_has_access_false_user_logged_in_group() { 146 $u = self::factory()->user->create(); 147 $g = self::factory()->group->create(); 148 $old_current_user = get_current_user_id(); 149 $this->set_current_user( $u ); 150 151 $group = groups_get_group( $g ); 152 153 $this->go_to( bp_get_group_permalink( $group ) ); 154 155 $subnav_item = array( 156 'user_has_access' => false, 157 'no_access_url' => bp_get_group_permalink( $group ), 158 ); 159 160 // Just test relevant info 161 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 162 $this->assertSame( 'failure', $found['status'] ); 163 $this->assertSame( bp_get_group_permalink( $group ), $found['redirect_args']['root'] ); 164 165 // Clean up 166 $this->set_current_user( $old_current_user ); 167 } 168 169 public function test_user_has_access_false_user_logged_in_group_no_redirect_url_provided() { 170 $u = self::factory()->user->create(); 171 $g = self::factory()->group->create(); 172 $old_current_user = get_current_user_id(); 173 $this->set_current_user( $u ); 174 175 $group = groups_get_group( $g ); 176 177 $this->go_to( bp_get_group_permalink( $group ) ); 178 179 $subnav_item = array( 180 'user_has_access' => false, 181 ); 182 183 // Just test relevant info 184 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 185 $this->assertSame( 'failure', $found['status'] ); 186 $this->assertSame( bp_get_root_domain(), $found['redirect_args']['root'] ); 187 188 // Clean up 189 $this->set_current_user( $old_current_user ); 190 } 191 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |