[ 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_BpCoreNewNavItem extends BP_UnitTestCase { 7 8 /** 9 * @expectedIncorrectUsage bp_nav 10 */ 11 public function test_user_nav() { 12 $bp_nav = buddypress()->bp_nav; 13 14 $u = self::factory()->user->create(); 15 $old_current_user = get_current_user_id(); 16 $this->set_current_user( $u ); 17 18 $this->go_to( bp_core_get_user_domain( $u ) ); 19 20 bp_core_new_nav_item( array( 21 'name' => 'Foo', 22 'slug' => 'foo', 23 'position' => 25, 24 'screen_function' => 'foo_screen_function', 25 'default_subnav_slug' => 'foo-sub' 26 ) ); 27 28 $expected = array( 29 'name' => 'Foo', 30 'slug' => 'foo', 31 'link' => trailingslashit( bp_core_get_user_domain( $u ) . 'foo' ), 32 'css_id' => 'foo', 33 'show_for_displayed_user' => true, 34 'position' => 25, 35 'screen_function' => 'foo_screen_function', 36 'default_subnav_slug' => 'foo-sub' 37 ); 38 39 foreach ( $expected as $k => $v ) { 40 $this->assertEquals( $v, buddypress()->bp_nav['foo'][ $k ] ); 41 } 42 43 // Clean up 44 buddypress()->bp_nav = $bp_nav; 45 $this->set_current_user( $old_current_user ); 46 } 47 48 /** 49 * @expectedIncorrectUsage bp_nav 50 */ 51 public function test_group_nav() { 52 $bp_nav = buddypress()->bp_nav; 53 54 $u = self::factory()->user->create(); 55 $g = self::factory()->group->create(); 56 $old_current_user = get_current_user_id(); 57 $this->set_current_user( $u ); 58 59 $group = groups_get_group( $g ); 60 61 $this->go_to( bp_get_group_permalink( $group ) ); 62 63 $this->assertTrue( buddypress()->bp_nav[ $group->slug ]['position'] === -1 ); 64 65 // Clean up 66 buddypress()->bp_nav = $bp_nav; 67 $this->set_current_user( $old_current_user ); 68 } 69 70 public function test_should_return_false_if_name_is_not_provided() { 71 $args = array( 72 'slug' => 'foo', 73 ); 74 75 $this->assertFalse( bp_core_new_nav_item( $args ) ); 76 } 77 78 public function test_should_return_false_if_slug_is_not_provided() { 79 $args = array( 80 'name' => 'foo', 81 ); 82 83 $this->assertFalse( bp_core_new_nav_item( $args ) ); 84 } 85 86 public function test_should_return_false_if_site_admin_only_and_current_user_cannot_bp_moderate() { 87 // Should already be set to a 0 user. 88 $this->assertFalse( bp_current_user_can( 'bp_moderate' ) ); 89 $args = array( 90 'name' => 'Foo', 91 'slug' => 'foo', 92 'site_admin_only' => true, 93 ); 94 95 $this->assertFalse( bp_core_new_nav_item( $args ) ); 96 } 97 98 /** 99 * @expectedIncorrectUsage bp_nav 100 */ 101 public function test_css_id_should_fall_back_on_slug() { 102 $args = array( 103 'name' => 'Foo', 104 'slug' => 'foo', 105 ); 106 bp_core_new_nav_item( $args ); 107 108 $this->assertSame( 'foo', buddypress()->bp_nav['foo']['css_id'] ); 109 } 110 111 /** 112 * @expectedIncorrectUsage bp_nav 113 */ 114 public function test_css_id_should_be_respected() { 115 $args = array( 116 'name' => 'Foo', 117 'slug' => 'foo', 118 'item_css_id' => 'bar', 119 ); 120 bp_core_new_nav_item( $args ); 121 122 $this->assertSame( 'bar', buddypress()->bp_nav['foo']['css_id'] ); 123 } 124 125 public function test_show_for_displayed_user_false_should_force_function_to_return_false_when_bp_user_has_access_is_also_false() { 126 $args = array( 127 'name' => 'Foo', 128 'slug' => 'foo', 129 'show_for_displayed_user' => false, 130 ); 131 132 add_filter( 'bp_user_has_access', '__return_false' ); 133 $retval = bp_core_new_nav_item( $args ); 134 remove_filter( 'bp_user_has_access', '__return_false' ); 135 136 $this->assertFalse( $retval ); 137 } 138 139 /** 140 * @expectedIncorrectUsage bp_nav 141 */ 142 public function test_existence_of_access_protected_user_nav() { 143 $bp_nav = buddypress()->bp_nav; 144 145 $u = self::factory()->user->create(); 146 $u2 = self::factory()->user->create(); 147 $old_current_user = get_current_user_id(); 148 $this->set_current_user( $u2 ); 149 150 $this->go_to( bp_core_get_user_domain( $u ) ); 151 152 $expected = array( 153 'name' => 'Settings', 154 'slug' => 'settings', 155 'link' => trailingslashit( bp_loggedin_user_domain() . 'settings' ), 156 'css_id' => 'settings', 157 'show_for_displayed_user' => false, 158 'position' => 100, 159 'screen_function' => 'bp_settings_screen_general', 160 'default_subnav_slug' => 'general' 161 ); 162 163 foreach ( $expected as $k => $v ) { 164 $this->assertEquals( $v, buddypress()->bp_nav['settings'][ $k ] ); 165 } 166 167 // Clean up 168 buddypress()->bp_nav = $bp_nav; 169 $this->set_current_user( $old_current_user ); 170 } 171 172 /** 173 * @expectedIncorrectUsage bp_nav 174 */ 175 public function test_creation_of_access_protected_user_nav() { 176 // The nav item must be added to bp_nav, even if the current user 177 // can't visit that nav item. 178 $bp_nav = buddypress()->bp_nav; 179 180 $u = self::factory()->user->create(); 181 $u2 = self::factory()->user->create(); 182 $old_current_user = get_current_user_id(); 183 $this->set_current_user( $u2 ); 184 185 $this->go_to( bp_core_get_user_domain( $u ) ); 186 187 bp_core_new_nav_item( array( 188 'name' => 'Woof', 189 'slug' => 'woof', 190 'show_for_displayed_user' => false, 191 'position' => 35, 192 'screen_function' => 'woof_screen_function', 193 'default_subnav_slug' => 'woof-one' 194 ) ); 195 196 $expected = array( 197 'name' => 'Woof', 198 'slug' => 'woof', 199 'link' => trailingslashit( bp_loggedin_user_domain() . 'woof' ), 200 'css_id' => 'woof', 201 'show_for_displayed_user' => false, 202 'position' => 35, 203 'screen_function' => 'woof_screen_function', 204 'default_subnav_slug' => 'woof-one' 205 ); 206 207 foreach ( $expected as $k => $v ) { 208 $this->assertEquals( $v, buddypress()->bp_nav['woof'][ $k ] ); 209 } 210 211 // Clean up 212 buddypress()->bp_nav = $bp_nav; 213 $this->set_current_user( $old_current_user ); 214 } 215 }
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 |