Changeset 13507
- Timestamp:
- 06/25/2023 05:18:41 PM (16 months ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-buddybar.php
r13503 r13507 858 858 $screen_functions = $bp->{$component}->nav->delete_nav( $slug ); 859 859 860 // Reset backcompat nav items so that subsequent references will be correct. 861 $bp->bp_nav->reset(); 862 $bp->bp_options_nav->reset(); 860 /** 861 * Fires when a nav item was removed from navigation. 862 * 863 * @since 12.0.0 864 * 865 * @param false|callable|array $screen_functions False, the screen function(s) on success. 866 * @param string $slug The slug of the primary navigation item. 867 * @param string|null $component The component the navigation is attached to. Defaults to 'members'. 868 */ 869 do_action( 'bp_core_removed_nav_item', $screen_functions, $slug, $component ); 863 870 864 871 if ( ! is_array( $screen_functions ) ) { … … 907 914 $screen_functions = $bp->{$component}->nav->delete_nav( $slug, $parent_slug ); 908 915 909 // Reset backcompat nav items so that subsequent references will be correct. 910 $bp->bp_nav->reset(); 911 $bp->bp_options_nav->reset(); 916 /** 917 * Fires when a subnav item was removed from navigation. 918 * 919 * @since 12.0.0 920 * 921 * @param false|callable|array $screen_functions False, the screen function(s) on success. 922 * @param string $parent_slug The slug of the primary navigation item. 923 * @param string $slug The slug of the secondary item to be removed. 924 * @param string|null $component The component the navigation is attached to. Defaults to 'members'. 925 */ 926 do_action( 'bp_core_removed_subnav_item', $screen_functions, $parent_slug, $slug, $component ); 912 927 913 928 if ( ! is_array( $screen_functions ) ) { -
trunk/src/bp-core/classes/class-bp-core-bp-nav-backcompat.php
r13500 r13507 4 4 * 5 5 * @since 2.6.0 6 * @deprecated 12.0.0 6 7 */ 7 8 … … 16 17 * 17 18 * @since 2.6.0 19 * @deprecated 12.0.0 18 20 */ 19 21 class BP_Core_BP_Nav_BackCompat implements ArrayAccess { … … 57 59 * 58 60 * @since 2.6.0 61 * @deprecated 12.0.0 59 62 * 60 63 * @param mixed $offset Array offset. … … 68 71 '2.6.0' 69 72 ); 70 71 $bp = buddypress(); 72 73 if ( is_array( $value ) ) { 74 $value = new self( $value ); 75 } 76 77 if ( $offset !== null ) { 78 // Temporarily set the backcompat_nav. 79 $this->backcompat_nav[ $offset ] = $value; 80 81 $args = $this->to_array(); 82 if ( isset( $args['parent_slug'] ) ) { 83 $this->get_component_nav( $args['parent_slug'] )->edit_nav( $args, $args['slug'], $args['parent_slug'] ); 84 } elseif ( isset( $args['slug'] ) ) { 85 $bp->members->nav->edit_nav( $args, $args['slug'] ); 86 } 87 } 73 _deprecated_function( __METHOD__, '12.0.0' ); 88 74 } 89 75 … … 92 78 * 93 79 * @since 2.6.0 80 * @deprecated 12.0.0 94 81 * 95 82 * @param mixed $offset Array offset. … … 103 90 '2.6.0' 104 91 ); 105 106 $nav = $this->get_nav( $offset ); 107 if ( $nav && isset( $nav[ $offset ] ) ) { 108 $this->backcompat_nav[ $offset ] = new self( $nav[ $offset ] ); 109 } 110 111 return $this->backcompat_nav[ $offset ]; 92 _deprecated_function( __METHOD__, '12.0.0' ); 112 93 } 113 94 … … 116 97 * 117 98 * @since 2.6.0 99 * @deprecated 12.0.0 118 100 * 119 101 * @param mixed $offset Array offset. … … 127 109 '2.6.0' 128 110 ); 129 130 if ( isset( $this->backcompat_nav[ $offset ] ) ) { 131 return true; 132 } 133 134 $nav = $this->get_nav( $offset ); 135 if ( $nav && isset( $nav[ $offset ] ) ) { 136 return true; 137 } 138 139 return false; 111 _deprecated_function( __METHOD__, '12.0.0' ); 140 112 } 141 113 … … 144 116 * 145 117 * @since 2.6.0 118 * @deprecated 12.0.0 146 119 * 147 120 * @param mixed $offset Array offset. … … 154 127 '2.6.0' 155 128 ); 156 157 // For top-level nav items, the backcompat nav hasn't yet been initialized. 158 if ( ! isset( $this->backcompat_nav[ $offset ] ) ) { 159 buddypress()->members->nav->delete_nav( $offset ); 160 unset( $this->backcompat_nav[ $offset ] ); 161 } 129 _deprecated_function( __METHOD__, '12.0.0' ); 162 130 } 163 131 … … 166 134 * 167 135 * @since 2.6.0 136 * @deprecated 12.0.0 168 137 * 169 138 * @param string $component 170 139 */ 171 140 public function set_component( $component ) { 172 $this->component = $component;141 _deprecated_function( __METHOD__, '12.0.0' ); 173 142 } 174 143 … … 181 150 * 182 151 * @since 2.6.0 152 * @deprecated 12.0.0 183 153 * 184 154 * @param mixed $offset Array offset. … … 186 156 */ 187 157 public function get_component( $offset = '' ) { 188 if ( ! isset( $this->component ) ) { 189 if ( bp_is_active( 'groups' ) && $offset === bp_get_current_group_slug() ) { 190 $this->component = 'groups'; 191 } else { 192 $this->component = 'members'; 193 } 194 } 195 196 return $this->component; 158 _deprecated_function( __METHOD__, '12.0.0' ); 197 159 } 198 160 … … 203 165 * 204 166 * @since 2.6.0 167 * @deprecated 12.0.0 205 168 */ 206 169 public function reset() { 207 $this->backcompat_nav = array();170 _deprecated_function( __METHOD__, '12.0.0' ); 208 171 } 209 172 … … 212 175 * 213 176 * @since 2.6.0 177 * @deprecated 12.0.0 214 178 * 215 179 * @param mixed $offset Array offset. … … 217 181 */ 218 182 protected function get_nav( $offset ) { 219 $component_nav = $this->get_component_nav( $offset ); 220 $primary_nav = $component_nav->get_primary( array( 'slug' => $offset ), false ); 221 222 $nav = array(); 223 224 if ( empty( $primary_nav ) ) { 225 return $nav; 226 } 227 228 foreach ( $primary_nav as $item ) { 229 $nav[ $item->slug ] = (array) $item; 230 } 231 232 return $nav; 183 _deprecated_function( __METHOD__, '12.0.0' ); 233 184 } 234 185 … … 243 194 * 244 195 * @since 2.6.0 196 * @deprecated 12.0.0 245 197 * 246 198 * @param string $offset Nav item name. … … 248 200 */ 249 201 protected function get_component_nav( $offset = '' ) { 250 $component = $this->get_component( $offset ); 251 252 $bp = buddypress(); 253 if ( ! isset( $bp->{$component}->nav ) ) { 254 return false; 255 } 256 257 return $bp->{$component}->nav; 202 _deprecated_function( __METHOD__, '12.0.0' ); 258 203 } 259 204 … … 262 207 * 263 208 * @since 2.6.0 209 * @deprecated 12.0.0 264 210 * 265 211 * @return array 266 212 */ 267 213 protected function to_array() { 268 return $this->backcompat_nav;214 _deprecated_function( __METHOD__, '12.0.0' ); 269 215 } 270 216 } -
trunk/src/bp-core/classes/class-bp-core-bp-options-nav-backcompat.php
r13504 r13507 4 4 * 5 5 * @since 2.6.0 6 * @deprecated 12.0.0 6 7 */ 7 8 … … 16 17 * 17 18 * @since 2.6.0 19 * @deprecated 12.0.0 18 20 */ 19 21 class BP_Core_BP_Options_Nav_BackCompat extends BP_Core_BP_Nav_BackCompat { … … 31 33 * 32 34 * @since 2.6.0 35 * @deprecated 12.0.0 33 36 * 34 37 * @param mixed $offset Array offset. … … 41 44 '2.6.0' 42 45 ); 43 44 if ( empty( $this->backcompat_nav[ $offset ] ) ) { 45 $nav = $this->get_nav( $offset ); 46 if ( $nav ) { 47 $subnavs = $this->get_component_nav( $offset )->get_secondary( array( 'parent_slug' => $offset ) ); 48 $subnav_keyed = array(); 49 if ( $subnavs ) { 50 foreach ( $subnavs as $subnav ) { 51 $subnav_keyed[ $subnav->slug ] = (array) $subnav; 52 } 53 } 54 55 $subnav_object = new self( $subnav_keyed ); 56 $subnav_object->set_component( $this->get_component() ); 57 $subnav_object->set_parent_slug( $offset ); 58 59 $this->backcompat_nav[ $offset ] = $subnav_object; 60 } 61 } 62 63 if ( isset( $this->backcompat_nav[ $offset ] ) ) { 64 return $this->backcompat_nav[ $offset ]; 65 } 66 67 return false; 46 _deprecated_function( __METHOD__, '12.0.0' ); 68 47 } 69 48 … … 72 51 * 73 52 * @since 2.6.0 53 * @deprecated 12.0.0 74 54 * 75 55 * @param mixed $offset Array offset. … … 81 61 '2.6.0' 82 62 ); 83 84 $this->get_component_nav( $offset )->delete_nav( $offset, $this->get_parent_slug() ); 85 86 // Clear the cached nav. 87 unset( $this->backcompat_nav[ $offset ] ); 63 _deprecated_function( __METHOD__, '12.0.0' ); 88 64 } 89 65 … … 92 68 * 93 69 * @since 2.6.0 70 * @deprecated 12.0.0 94 71 * 95 72 * @return string 96 73 */ 97 74 public function get_parent_slug() { 98 return $this->parent_slug;75 _deprecated_function( __METHOD__, '12.0.0' ); 99 76 } 100 77 … … 103 80 * 104 81 * @since 2.6.0 82 * @deprecated 12.0.0 105 83 */ 106 84 public function set_parent_slug( $slug ) { 107 $this->parent_slug = $slug;85 _deprecated_function( __METHOD__, '12.0.0' ); 108 86 } 109 87 … … 112 90 * 113 91 * @since 2.6.0 92 * @deprecated 12.0.0 114 93 * 115 94 * @param mixed $offset Array offset. … … 117 96 */ 118 97 public function get_nav( $offset ) { 119 $nav = parent::get_nav( $offset ); 120 121 if ( ! $nav ) { 122 $component_nav = $this->get_component_nav( $offset ); 123 $secondary_nav = $component_nav->get_secondary( array( 'slug' => $offset ), false ); 124 125 $nav = array(); 126 127 if ( empty( $secondary_nav ) ) { 128 return $nav; 129 } 130 131 foreach ( $secondary_nav as $item ) { 132 $nav[ $item->slug ] = (array) $item; 133 } 134 } 135 136 return $nav; 98 _deprecated_function( __METHOD__, '12.0.0' ); 137 99 } 138 100 } -
trunk/src/bp-core/classes/class-bp-core.php
r13492 r13507 276 276 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user ); 277 277 278 // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties. 279 $bp->bp_nav = new BP_Core_BP_Nav_BackCompat(); 280 $bp->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat(); 278 // Only fully deprecate the legacy navigation globals if BP Classic is not active. 279 if ( ! function_exists( 'bp_classic' ) ) { 280 // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties. 281 $bp->bp_nav = new BP_Core_BP_Nav_BackCompat(); 282 $bp->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat(); 283 } 281 284 282 285 /** -
trunk/tests/phpunit/testcases/core/nav/bpCoreNewNavItem.php
r13441 r13507 16 16 17 17 parent::tear_down(); 18 }19 20 /**21 * @expectedIncorrectUsage bp_nav22 */23 public function test_user_nav() {24 $bp_nav = buddypress()->bp_nav;25 26 $u = self::factory()->user->create();27 $old_current_user = get_current_user_id();28 $this->set_current_user( $u );29 $this->set_permalink_structure( '/%postname%/' );30 31 $this->go_to( bp_members_get_user_url( $u ) );32 33 bp_core_new_nav_item( array(34 'name' => 'Foo',35 'slug' => 'foo',36 'position' => 25,37 'screen_function' => 'foo_screen_function',38 'default_subnav_slug' => 'foo-sub'39 ) );40 41 $expected = array(42 'name' => 'Foo',43 'slug' => 'foo',44 'link' => bp_members_get_user_url(45 $u,46 array(47 'single_item_component' => 'foo',48 )49 ),50 'css_id' => 'foo',51 'show_for_displayed_user' => true,52 'position' => 25,53 'screen_function' => 'foo_screen_function',54 'default_subnav_slug' => 'foo-sub'55 );56 57 foreach ( $expected as $k => $v ) {58 $this->assertEquals( $v, buddypress()->bp_nav['foo'][ $k ] );59 }60 61 // Clean up62 buddypress()->bp_nav = $bp_nav;63 $this->set_current_user( $old_current_user );64 }65 66 /**67 * @expectedIncorrectUsage bp_nav68 */69 public function test_group_nav() {70 $bp_nav = buddypress()->bp_nav;71 72 $u = self::factory()->user->create();73 $g = self::factory()->group->create();74 $old_current_user = get_current_user_id();75 $this->set_current_user( $u );76 $this->set_permalink_structure( '/%postname%/' );77 78 $group = groups_get_group( $g );79 80 $this->go_to( bp_get_group_url( $group ) );81 82 $this->assertTrue( buddypress()->bp_nav[ $group->slug ]['position'] === -1 );83 84 // Clean up85 buddypress()->bp_nav = $bp_nav;86 $this->set_current_user( $old_current_user );87 18 } 88 19 … … 115 46 } 116 47 117 /**118 * @expectedIncorrectUsage bp_nav119 */120 public function test_css_id_should_fall_back_on_slug() {121 $args = array(122 'name' => 'Foo',123 'slug' => 'foo',124 );125 bp_core_new_nav_item( $args );126 127 $this->assertSame( 'foo', buddypress()->bp_nav['foo']['css_id'] );128 }129 130 /**131 * @expectedIncorrectUsage bp_nav132 */133 public function test_css_id_should_be_respected() {134 $args = array(135 'name' => 'Foo',136 'slug' => 'foo',137 'item_css_id' => 'bar',138 );139 bp_core_new_nav_item( $args );140 141 $this->assertSame( 'bar', buddypress()->bp_nav['foo']['css_id'] );142 }143 144 48 public function test_show_for_displayed_user_false_should_force_function_to_return_false_when_bp_user_has_access_is_also_false() { 145 49 $args = array( … … 155 59 $this->assertFalse( $retval ); 156 60 } 157 158 /**159 * @expectedIncorrectUsage bp_nav160 */161 public function test_existence_of_access_protected_user_nav() {162 $bp_nav = buddypress()->bp_nav;163 164 $u = self::factory()->user->create();165 $u2 = self::factory()->user->create();166 $old_current_user = get_current_user_id();167 $this->set_current_user( $u2 );168 $this->set_permalink_structure( '/%postname%/' );169 170 $this->go_to( bp_members_get_user_url( $u ) );171 172 $expected = array(173 'name' => 'Settings',174 'slug' => 'settings',175 'link' => bp_members_get_user_url(176 $u,177 array(178 'single_item_component' => 'settings',179 )180 ),181 'css_id' => 'settings',182 'show_for_displayed_user' => false,183 'position' => 100,184 'screen_function' => 'bp_settings_screen_general',185 'default_subnav_slug' => 'general'186 );187 188 foreach ( $expected as $k => $v ) {189 $this->assertEquals( $v, buddypress()->bp_nav['settings'][ $k ] );190 }191 192 // Clean up193 buddypress()->bp_nav = $bp_nav;194 $this->set_current_user( $old_current_user );195 }196 197 /**198 * @expectedIncorrectUsage bp_nav199 */200 public function test_creation_of_access_protected_user_nav() {201 // The nav item must be added to bp_nav, even if the current user202 // can't visit that nav item.203 $bp_nav = buddypress()->bp_nav;204 205 $u = self::factory()->user->create();206 $u2 = self::factory()->user->create();207 $old_current_user = get_current_user_id();208 $this->set_current_user( $u2 );209 $this->set_permalink_structure( '/%postname%/' );210 211 $this->go_to( bp_members_get_user_url( $u ) );212 213 bp_core_new_nav_item( array(214 'name' => 'Woof',215 'slug' => 'woof',216 'show_for_displayed_user' => false,217 'position' => 35,218 'screen_function' => 'woof_screen_function',219 'default_subnav_slug' => 'woof-one'220 ) );221 222 $expected = array(223 'name' => 'Woof',224 'slug' => 'woof',225 'link' => bp_members_get_user_url(226 $u,227 array(228 'single_item_component' => 'woof',229 )230 ),231 'css_id' => 'woof',232 'show_for_displayed_user' => false,233 'position' => 35,234 'screen_function' => 'woof_screen_function',235 'default_subnav_slug' => 'woof-one'236 );237 238 foreach ( $expected as $k => $v ) {239 $this->assertEquals( $v, buddypress()->bp_nav['woof'][ $k ] );240 }241 242 // Clean up243 buddypress()->bp_nav = $bp_nav;244 $this->set_current_user( $old_current_user );245 }246 61 } -
trunk/tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php
r13468 r13507 16 16 17 17 parent::tear_down(); 18 }19 20 /**21 * @expectedIncorrectUsage bp_nav22 */23 public function test_user_subnav() {24 $this->set_permalink_structure( '/%postname%/' );25 $bp_options_nav = buddypress()->bp_options_nav;26 27 $u = self::factory()->user->create();28 $old_current_user = get_current_user_id();29 $this->set_current_user( $u );30 31 $this->go_to( bp_members_get_user_url( $u ) );32 33 bp_core_new_nav_item( array(34 'name' => 'Foo Parent',35 'slug' => 'foo-parent',36 'screen_function' => 'foo_screen_function',37 'position' => 10,38 ) );39 40 bp_core_new_subnav_item( array(41 'name' => 'Foo',42 'slug' => 'foo',43 'parent_url' => bp_members_get_user_url(44 $u,45 array(46 'single_item_component' => 'foo-parent',47 )48 ),49 'parent_slug' => 'foo-parent',50 'screen_function' => 'foo_screen_function',51 'position' => 1052 ) );53 54 $expected = array(55 'name' => 'Foo',56 'link' => bp_members_get_user_url(57 $u,58 array(59 'single_item_component' => 'foo-parent',60 'single_item_action' => 'foo',61 )62 ),63 'slug' => 'foo',64 'css_id' => 'foo',65 'position' => 10,66 'user_has_access' => true,67 'no_access_url' => '',68 'screen_function' => 'foo_screen_function',69 'show_in_admin_bar' => false,70 );71 72 foreach ( $expected as $k => $v ) {73 $this->assertSame( $v, buddypress()->bp_options_nav['foo-parent']['foo'][ $k ] );74 }75 76 // Clean up77 buddypress()->bp_options_nav = $bp_options_nav;78 $this->set_current_user( $old_current_user );79 18 } 80 19 … … 125 64 } 126 65 127 /**128 * @expectedIncorrectUsage bp_nav129 */130 public function test_link_provided() {131 $bp_options_nav = buddypress()->bp_options_nav;132 133 bp_core_new_nav_item( array(134 'name' => 'Foo',135 'slug' => 'foo',136 'screen_function' => 'foo',137 'link' => 'https://buddypress.org/',138 ) );139 140 bp_core_new_subnav_item( array(141 'name' => 'bar',142 'slug' => 'bar',143 'parent_slug' => 'foo',144 'parent_url' => 'foo',145 'screen_function' => 'foo',146 'link' => 'https://buddypress.org/',147 ) );148 149 $this->assertSame( 'https://buddypress.org/', buddypress()->bp_options_nav['foo']['bar']['link'] );150 151 buddypress()->bp_options_nav = $bp_options_nav;152 }153 154 /**155 * @expectedIncorrectUsage bp_nav156 */157 public function test_link_built_from_parent_url_and_slug() {158 $bp_options_nav = buddypress()->bp_options_nav;159 160 bp_core_new_nav_item( array(161 'name' => 'Foo',162 'slug' => 'foo',163 'screen_function' => 'foo',164 'link' => 'https://buddypress.org/',165 ) );166 167 bp_core_new_subnav_item( array(168 'name' => 'bar',169 'slug' => 'bar',170 'parent_slug' => 'foo',171 'parent_url' => 'http://example.com/foo/',172 'screen_function' => 'foo',173 ) );174 175 $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav['foo']['bar']['link'] );176 177 buddypress()->bp_options_nav = $bp_options_nav;178 }179 180 /**181 * @expectedIncorrectUsage bp_nav182 */183 public function test_link_built_from_parent_url_and_slug_where_slug_is_default() {184 $bp_nav = buddypress()->bp_nav;185 $bp_options_nav = buddypress()->bp_options_nav;186 187 bp_core_new_nav_item( array(188 'name' => 'Foo',189 'slug' => 'foo',190 'url' => 'http://example.com/foo/',191 'screen_function' => 'foo',192 'default_subnav_slug' => 'bar',193 ) );194 195 bp_core_new_subnav_item( array(196 'name' => 'bar',197 'slug' => 'bar',198 'parent_slug' => 'foo',199 'parent_url' => 'http://example.com/foo/',200 'screen_function' => 'foo',201 ) );202 203 $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav['foo']['bar']['link'] );204 205 // clean up206 buddypress()->bp_nav = $bp_nav;207 buddypress()->bp_options_nav = $bp_options_nav;208 }209 210 /**211 * @expectedIncorrectUsage bp_nav212 */213 public function test_should_trailingslash_link_when_link_is_autogenerated_using_slug() {214 $this->set_permalink_structure( '/%postname%/' );215 bp_core_new_nav_item( array(216 'name' => 'Foo',217 'slug' => 'foo',218 'screen_function' => 'foo',219 'link' => 'https://buddypress.org/',220 ) );221 222 bp_core_new_subnav_item( array(223 'name' => 'bar',224 'slug' => 'bar',225 'parent_slug' => 'foo',226 'parent_url' => bp_get_root_url() . 'foo/',227 'screen_function' => 'foo',228 ) );229 230 $expected = bp_get_root_url() . 'foo/bar/';231 $this->assertSame( $expected, buddypress()->bp_options_nav['foo']['bar']['link'] );232 }233 234 /**235 * @expectedIncorrectUsage bp_nav236 */237 public function test_should_trailingslash_link_when_link_is_autogenerated_not_using_slug() {238 $this->set_permalink_structure( '/%postname%/' );239 bp_core_new_nav_item( array(240 'name' => 'foo',241 'slug' => 'foo-parent',242 'link' => bp_get_root_url() . 'foo-parent/',243 'default_subnav_slug' => 'bar',244 'screen_function' => 'foo',245 ) );246 247 bp_core_new_subnav_item( array(248 'name' => 'bar',249 'slug' => 'bar',250 'parent_slug' => 'foo-parent',251 'parent_url' => bp_get_root_url() . '/foo-parent/',252 'screen_function' => 'bar',253 ) );254 255 $expected = bp_get_root_url() . '/foo-parent/bar/';256 $this->assertSame( $expected, buddypress()->bp_options_nav['foo-parent']['bar']['link'] );257 }258 259 /**260 * @ticket BP6353261 * @expectedIncorrectUsage bp_nav262 */263 public function test_link_should_not_trailingslash_link_explicit_link() {264 $link = 'http://example.com/foo/bar/blah/?action=edit&id=30';265 266 bp_core_new_nav_item( array(267 'name' => 'Foo',268 'slug' => 'foo',269 'screen_function' => 'foo',270 'link' => 'http://example.com/foo/',271 ) );272 273 bp_core_new_subnav_item( array(274 'name' => 'bar',275 'slug' => 'bar',276 'parent_slug' => 'foo',277 'parent_url' => 'http://example.com/foo/',278 'screen_function' => 'foo',279 'link' => $link,280 ) );281 282 $this->assertSame( $link, buddypress()->bp_options_nav['foo']['bar']['link'] );283 }284 285 66 public function test_should_return_false_if_site_admin_only_and_current_user_cannot_bp_moderate() { 286 67 bp_core_new_nav_item( array( … … 302 83 303 84 $this->assertFalse( bp_core_new_subnav_item( $args ) ); 304 }305 306 /**307 * @expectedIncorrectUsage bp_nav308 */309 public function test_css_id_should_fall_back_on_slug() {310 bp_core_new_nav_item( array(311 'name' => 'Parent',312 'slug' => 'parent',313 'screen_function' => 'foo',314 ) );315 316 $args = array(317 'name' => 'Foo',318 'slug' => 'foo',319 'parent_slug' => 'parent',320 'parent_url' => bp_get_root_url() . '/parent/',321 'screen_function' => 'foo',322 );323 bp_core_new_subnav_item( $args );324 325 $this->assertSame( 'foo', buddypress()->bp_options_nav['parent']['foo']['css_id'] );326 }327 328 /**329 * @expectedIncorrectUsage bp_nav330 */331 public function test_css_id_should_be_respected() {332 bp_core_new_nav_item( array(333 'name' => 'Parent',334 'slug' => 'parent',335 'screen_function' => 'foo',336 ) );337 338 $args = array(339 'name' => 'Foo',340 'slug' => 'foo',341 'parent_slug' => 'parent',342 'parent_url' => bp_get_root_url() . '/parent/',343 'screen_function' => 'foo',344 'item_css_id' => 'bar',345 );346 bp_core_new_subnav_item( $args );347 348 $this->assertSame( 'bar', buddypress()->bp_options_nav['parent']['foo']['css_id'] );349 85 } 350 86 … … 370 106 public function test_subnav_should_not_404_on_early_bp_setup_nav_priority() { 371 107 // Register a subnav on 'bp_setup_nav' hook early (at priority zero). 372 add_action( 'bp_setup_nav', array( $this, ' screen_callback' ), 0 );108 add_action( 'bp_setup_nav', array( $this, 'new_nav_hook' ), 0 ); 373 109 374 110 $u = self::factory()->user->create(); … … 390 126 $this->assertFalse( is_404() ); 391 127 392 remove_action( 'bp_setup_nav', array( $this, ' screen_callback' ), 0 );128 remove_action( 'bp_setup_nav', array( $this, 'new_nav_hook' ), 0 ); 393 129 394 130 $this->set_current_user( $old_current_user ); -
trunk/tests/phpunit/testcases/core/nav/bpCoreRemoveNavItem.php
r11256 r13507 6 6 */ 7 7 class BP_Tests_Core_Nav_BpCoreRemoveNavItem extends BP_UnitTestCase { 8 /**9 * @expectedIncorrectUsage bp_nav10 */11 public function test_should_remove_subnav_items() {12 $bp = buddypress();13 14 $_bp_nav = $bp->bp_nav;15 $_bp_options_nav = $bp->bp_options_nav;16 17 bp_core_new_nav_item( array(18 'name' => 'Foo',19 'slug' => 'foo',20 'screen_function' => 'foo',21 ) );22 23 bp_core_new_subnav_item( array(24 'name' => 'Bar',25 'slug' => 'bar',26 'parent_slug' => 'foo',27 'parent_url' => 'foo',28 'screen_function' => 'bar',29 ) );30 31 $this->assertTrue( isset( $bp->bp_nav['foo'] ) );32 $this->assertTrue( isset( $bp->bp_options_nav['foo'] ) );33 $this->assertTrue( isset( $bp->bp_options_nav['foo']['bar'] ) );34 35 bp_core_remove_nav_item( 'foo' );36 37 $this->assertFalse( isset( $bp->bp_options_nav['foo']['bar'] ) );38 39 $bp->bp_nav = $_bp_nav;40 $bp->bp_options_nav = $_bp_options_nav;41 }42 43 /**44 * @expectedIncorrectUsage bp_nav45 */46 public function test_should_remove_nav_item() {47 $bp = buddypress();48 49 $_bp_nav = $bp->bp_nav;50 $_bp_options_nav = $bp->bp_options_nav;51 52 bp_core_new_nav_item( array(53 'name' => 'Foo',54 'slug' => 'foo',55 'screen_function' => 'foo',56 ) );57 58 $this->assertTrue( isset( $bp->bp_nav['foo'] ) );59 60 bp_core_remove_nav_item( 'foo' );61 62 $this->assertFalse( isset( $bp->bp_nav['foo'] ) );63 64 $bp->bp_nav = $_bp_nav;65 $bp->bp_options_nav = $_bp_options_nav;66 }67 68 8 /** 69 9 * @ticket BP7203 -
trunk/tests/phpunit/testcases/core/nav/bpCoreRemoveSubnavItem.php
r13437 r13507 6 6 */ 7 7 class BP_Tests_Core_Nav_BpCoreRemoveSubnavItem extends BP_UnitTestCase { 8 /**9 * @expectedIncorrectUsage bp_nav10 */11 public function test_should_remove_subnav_item() {12 $bp = buddypress();13 14 $_bp_nav = $bp->bp_nav;15 $_bp_options_nav = $bp->bp_options_nav;16 17 bp_core_new_nav_item( array(18 'name' => 'Foo',19 'slug' => 'foo',20 'screen_function' => 'foo',21 ) );22 23 bp_core_new_subnav_item( array(24 'name' => 'Bar',25 'slug' => 'bar',26 'parent_slug' => 'foo',27 'parent_url' => 'foo',28 'screen_function' => 'bar',29 ) );30 31 $this->assertTrue( isset( $bp->bp_options_nav['foo']['bar'] ) );32 33 bp_core_remove_subnav_item( 'foo', 'bar' );34 35 $this->assertFalse( isset( $bp->bp_options_nav['foo']['bar'] ) );36 37 $bp->bp_nav = $_bp_nav;38 $bp->bp_options_nav = $_bp_options_nav;39 }40 41 /**42 * @expectedIncorrectUsage bp_nav43 */44 public function test_should_fail_on_incorrect_parent() {45 $bp = buddypress();46 47 $_bp_nav = $bp->bp_nav;48 $_bp_options_nav = $bp->bp_options_nav;49 50 bp_core_new_nav_item( array(51 'name' => 'Foo',52 'slug' => 'foo',53 'screen_function' => 'foo',54 ) );55 56 bp_core_new_subnav_item( array(57 'name' => 'Bar',58 'slug' => 'bar',59 'parent_slug' => 'foo',60 'parent_url' => 'foo',61 'screen_function' => 'bar',62 ) );63 64 $this->assertTrue( isset( $bp->bp_options_nav['foo']['bar'] ) );65 66 bp_core_remove_subnav_item( 'bad-parent', 'bar' );67 68 $this->assertTrue( isset( $bp->bp_options_nav['foo']['bar'] ) );69 70 $bp->bp_nav = $_bp_nav;71 $bp->bp_options_nav = $_bp_options_nav;72 }73 8 74 9 public function test_backcompat_remove_group_nav_items() { -
trunk/tests/phpunit/testcases/groups/class-bp-group-extension.php
r13441 r13507 229 229 230 230 /** 231 * @group enable_nav_item232 * @expectedIncorrectUsage bp_nav233 */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 up251 buddypress()->bp_options_nav = $old_options_nav;252 }253 254 /**255 * @group enable_nav_item256 * @expectedIncorrectUsage bp_nav257 */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 up275 buddypress()->bp_options_nav = $old_options_nav;276 }277 278 /**279 * @group visibility280 * @expectedIncorrectUsage bp_nav281 */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 user296 $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 up302 buddypress()->bp_options_nav = $old_options_nav;303 304 // Test as group member305 $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 up313 buddypress()->bp_options_nav = $old_options_nav;314 $this->set_current_user( $old_current_user );315 }316 317 /**318 * @group visibility319 * @expectedIncorrectUsage bp_nav320 *321 * visibility=public + status=private results in adding the item to322 * the nav. However, BP_Groups_Component::setup_globals() bounces the323 * user away from this page on a regular pageload (BP 2.0 and under)324 *325 * @see https://buddypress.trac.wordpress.org/ticket/4785326 */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 user341 $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 up347 buddypress()->bp_options_nav = $old_options_nav;348 349 // Test as group member350 $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 up358 buddypress()->bp_options_nav = $old_options_nav;359 $this->set_current_user( $old_current_user );360 }361 362 /**363 231 * @group user_can_visit 364 232 */ -
trunk/tests/phpunit/testcases/routing/core.php
r13461 r13507 21 21 $this->set_permalink_structure( $this->permalink_structure ); 22 22 } 23 23 24 function test_wordpress_page() { 24 25 $this->set_permalink_structure( '/%postname%/' ); … … 26 27 $this->assertEmpty( bp_current_component() ); 27 28 } 28 29 /**30 * @expectedIncorrectUsage bp_nav31 */32 function test_nav_menu() {33 $this->set_permalink_structure( '/%postname%/' );34 $this->go_to( '/' );35 $this->assertTrue( isset( buddypress()->bp_nav['activity'] ) );36 $this->assertTrue( isset( buddypress()->bp_nav['profile'] ) );37 }38 29 }
Note: See TracChangeset
for help on using the changeset viewer.