- Timestamp:
- 06/25/2023 05:18:41 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 );
Note: See TracChangeset
for help on using the changeset viewer.