Changeset 9988
- Timestamp:
- 07/02/2015 07:33:22 PM (9 years ago)
- Location:
- trunk/tests/phpunit/testcases/core
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/core/nav.php
r9819 r9988 6 6 */ 7 7 class BP_Tests_Core_Nav extends BP_UnitTestCase { 8 9 /**10 * @group bp_core_new_nav_item11 */12 public function test_bp_core_new_nav_item_user_nav() {13 $bp_nav = buddypress()->bp_nav;14 15 $u = $this->factory->user->create();16 $old_current_user = get_current_user_id();17 $this->set_current_user( $u );18 19 $this->go_to( bp_core_get_user_domain( $u ) );20 21 bp_core_new_nav_item( array(22 'name' => 'Foo',23 'slug' => 'foo',24 'position' => 25,25 'screen_function' => 'foo_screen_function',26 'default_subnav_slug' => 'foo-sub'27 ) );28 29 $expected = array(30 'name' => 'Foo',31 'slug' => 'foo',32 'link' => trailingslashit( bp_core_get_user_domain( $u ) . 'foo' ),33 'css_id' => 'foo',34 'show_for_displayed_user' => true,35 'position' => 25,36 'screen_function' => 'foo_screen_function',37 'default_subnav_slug' => 'foo-sub'38 );39 40 $this->assertSame( buddypress()->bp_nav['foo'], $expected );41 42 // Clean up43 buddypress()->bp_nav = $bp_nav;44 $this->set_current_user( $old_current_user );45 }46 47 /**48 * @group bp_core_new_nav_item49 */50 public function test_bp_core_new_nav_item_group_nav() {51 $bp_nav = buddypress()->bp_nav;52 53 $u = $this->factory->user->create();54 $g = $this->factory->group->create();55 $old_current_user = get_current_user_id();56 $this->set_current_user( $u );57 58 $group = groups_get_group( array(59 'group_id' => $g,60 ) );61 62 $this->go_to( bp_get_group_permalink( $group ) );63 64 $this->assertTrue( buddypress()->bp_nav[ $group->slug ]['position'] === -1 );65 66 // Clean up67 buddypress()->bp_nav = $bp_nav;68 $this->set_current_user( $old_current_user );69 }70 8 71 9 /** … … 107 45 buddypress()->bp_nav = $bp_nav; 108 46 $this->set_current_user( $old_current_user ); 109 }110 111 /**112 * @group bp_core_new_subnav_item113 */114 public function test_bp_core_new_subnav_item_user_subnav() {115 $bp_options_nav = buddypress()->bp_options_nav;116 117 $u = $this->factory->user->create();118 $old_current_user = get_current_user_id();119 $this->set_current_user( $u );120 121 $user_domain = bp_core_get_user_domain( $u );122 123 $this->go_to( $user_domain );124 125 bp_core_new_subnav_item( array(126 'name' => 'Foo',127 'slug' => 'foo',128 'parent_url' => trailingslashit( $user_domain . 'foo' ),129 'parent_slug' => 'foo',130 'screen_function' => 'foo_screen_function',131 'position' => 10132 ) );133 134 $expected = array(135 'name' => 'Foo',136 'link' => trailingslashit( $user_domain . 'foo/foo' ),137 'slug' => 'foo',138 'css_id' => 'foo',139 'position' => 10,140 'user_has_access' => true,141 'no_access_url' => '',142 'screen_function' => 'foo_screen_function',143 'show_in_admin_bar' => false,144 );145 146 $this->assertSame( buddypress()->bp_options_nav['foo']['foo'], $expected );147 148 // Clean up149 buddypress()->bp_options_nav = $bp_options_nav;150 $this->set_current_user( $old_current_user );151 }152 153 /**154 * @group bp_core_new_subnav_item155 */156 public function test_bp_core_new_subnav_item_required_params() {157 // 'name'158 $this->assertFalse( bp_core_new_subnav_item( array(159 'slug' => 'foo',160 'parent_slug' => 'foo',161 'parent_url' => 'foo',162 'screen_function' => 'foo',163 ) ) );164 165 // 'slug'166 $this->assertFalse( bp_core_new_subnav_item( array(167 'name' => 'foo',168 'parent_slug' => 'foo',169 'parent_url' => 'foo',170 'screen_function' => 'foo',171 ) ) );172 173 // 'parent_slug'174 $this->assertFalse( bp_core_new_subnav_item( array(175 'name' => 'foo',176 'slug' => 'foo',177 'parent_url' => 'foo',178 'screen_function' => 'foo',179 ) ) );180 181 // 'parent_url'182 $this->assertFalse( bp_core_new_subnav_item( array(183 'name' => 'foo',184 'slug' => 'foo',185 'parent_slug' => 'foo',186 'screen_function' => 'foo',187 ) ) );188 189 // 'screen_function'190 $this->assertFalse( bp_core_new_subnav_item( array(191 'name' => 'foo',192 'slug' => 'foo',193 'parent_slug' => 'foo',194 'parent_url' => 'foo',195 ) ) );196 }197 198 /**199 * @group bp_core_new_subnav_item200 */201 public function test_bp_core_new_subnav_item_site_admin_only() {202 $old_current_user = get_current_user_id();203 $this->set_current_user( 0 );204 205 $this->assertFalse( bp_core_new_subnav_item( array(206 'name' => 'foo',207 'slug' => 'foo',208 'parent_slug' => 'foo',209 'parent_url' => 'foo',210 'screen_function' => 'foo',211 'site_admin_only' => true,212 ) ) );213 214 $this->set_current_user( $old_current_user );215 }216 217 /**218 * @group bp_core_new_subnav_item219 */220 public function test_bp_core_new_subnav_item_link_provided() {221 $bp_options_nav = buddypress()->bp_options_nav;222 223 bp_core_new_subnav_item( array(224 'name' => 'bar',225 'slug' => 'bar',226 'parent_slug' => 'foo',227 'parent_url' => 'foo',228 'screen_function' => 'foo',229 'link' => 'https://buddypress.org/',230 ) );231 232 $this->assertSame( 'https://buddypress.org/', buddypress()->bp_options_nav['foo']['bar']['link'] );233 234 buddypress()->bp_options_nav = $bp_options_nav;235 }236 237 /**238 * @group bp_core_new_subnav_item239 */240 public function test_bp_core_new_subnav_item_link_built_from_parent_url_and_slug() {241 $bp_options_nav = buddypress()->bp_options_nav;242 243 bp_core_new_subnav_item( array(244 'name' => 'bar',245 'slug' => 'bar',246 'parent_slug' => 'foo',247 'parent_url' => 'http://example.com/foo/',248 'screen_function' => 'foo',249 ) );250 251 $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav['foo']['bar']['link'] );252 253 buddypress()->bp_options_nav = $bp_options_nav;254 }255 256 /**257 * @group bp_core_new_subnav_item258 */259 public function test_bp_core_new_subnav_item_link_built_from_parent_url_and_slug_where_slug_is_default() {260 $bp_nav = buddypress()->bp_nav;261 $bp_options_nav = buddypress()->bp_options_nav;262 263 // fake the parent264 buddypress()->bp_nav = array(265 'foo' => array(266 'default_subnav_slug' => 'bar',267 ),268 );269 270 bp_core_new_subnav_item( array(271 'name' => 'bar',272 'slug' => 'bar',273 'parent_slug' => 'foo',274 'parent_url' => 'http://example.com/foo/',275 'screen_function' => 'foo',276 ) );277 278 $this->assertSame( 'http://example.com/foo/', buddypress()->bp_options_nav['foo']['bar']['link'] );279 280 // clean up281 buddypress()->bp_nav = $bp_nav;282 buddypress()->bp_options_nav = $bp_options_nav;283 }284 285 /**286 * @group bp_core_maybe_hook_new_subnav_screen_function287 */288 public function test_maybe_hook_new_subnav_screen_function_user_has_access_true_no_callable_function() {289 $subnav_item = array(290 'user_has_access' => true,291 'screen_function' => '123foo456',292 );293 294 $expected = array(295 'status' => 'failure',296 );297 298 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );299 }300 301 /**302 * @group bp_core_maybe_hook_new_subnav_screen_function303 */304 public function test_maybe_hook_new_subnav_screen_function_user_has_access_true_callable_function() {305 $subnav_item = array(306 'user_has_access' => true,307 'screen_function' => 'wptexturize', // any old callable function308 );309 310 $expected = array(311 'status' => 'success',312 );313 314 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );315 316 // clean up317 remove_action( 'bp_screens', 'wptexturize', 3 );318 }319 320 /**321 * @group bp_core_maybe_hook_new_subnav_screen_function322 */323 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_out() {324 $old_current_user = get_current_user_id();325 $this->set_current_user( 0 );326 327 $subnav_item = array(328 'user_has_access' => false,329 );330 331 $expected = array(332 'status' => 'failure',333 'redirect_args' => array(),334 );335 336 $this->assertSame( $expected, bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) );337 338 $this->set_current_user( $old_current_user );339 }340 341 /**342 * @group bp_core_maybe_hook_new_subnav_screen_function343 */344 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_my_profile() {345 $u = $this->factory->user->create();346 $old_current_user = get_current_user_id();347 $this->set_current_user( $u );348 349 $this->go_to( bp_core_get_user_domain( $u ) );350 351 $subnav_item = array(352 'user_has_access' => false,353 );354 355 // Just test relevant info356 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );357 $this->assertSame( 'failure', $found['status'] );358 $this->assertSame( bp_core_get_user_domain( $u ), $found['redirect_args']['root'] );359 360 $this->set_current_user( $old_current_user );361 }362 363 /**364 * @group bp_core_maybe_hook_new_subnav_screen_function365 */366 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_others_profile_default_component_accessible() {367 $u1 = $this->factory->user->create();368 $u2 = $this->factory->user->create();369 $old_current_user = get_current_user_id();370 $this->set_current_user( $u1 );371 372 $this->go_to( bp_core_get_user_domain( $u2 ) );373 374 $old_bp_nav = buddypress()->bp_nav;375 $old_default_component = buddypress()->default_component;376 buddypress()->default_component = 'foo';377 buddypress()->bp_nav = array(378 'foo' => array(379 'show_for_displayed_user' => true,380 ),381 );382 383 $subnav_item = array(384 'user_has_access' => false,385 );386 387 // Just test relevant info388 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );389 $this->assertSame( 'failure', $found['status'] );390 $this->assertSame( bp_core_get_user_domain( $u2 ), $found['redirect_args']['root'] );391 392 // Clean up393 $this->set_current_user( $old_current_user );394 buddypress()->default_component = $old_default_component;395 buddypress()->bp_nav = $old_bp_nav;396 }397 398 /**399 * @group bp_core_maybe_hook_new_subnav_screen_function400 */401 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_others_profile_default_component_not_accessible() {402 $u1 = $this->factory->user->create();403 $u2 = $this->factory->user->create();404 $old_current_user = get_current_user_id();405 $this->set_current_user( $u1 );406 407 $this->go_to( bp_core_get_user_domain( $u2 ) );408 409 $old_bp_nav = buddypress()->bp_nav;410 $old_default_component = buddypress()->default_component;411 buddypress()->default_component = 'foo';412 buddypress()->bp_nav = array(413 'foo' => array(414 'show_for_displayed_user' => false,415 ),416 );417 418 $subnav_item = array(419 'user_has_access' => false,420 );421 422 // Just test relevant info423 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );424 $this->assertSame( 'failure', $found['status'] );425 $this->assertSame( bp_core_get_user_domain( $u2 ) . bp_get_activity_slug() . '/', $found['redirect_args']['root'] );426 427 // Clean up428 $this->set_current_user( $old_current_user );429 buddypress()->default_component = $old_default_component;430 buddypress()->bp_nav = $old_bp_nav;431 }432 433 /**434 * @group bp_core_maybe_hook_new_subnav_screen_function435 */436 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_group() {437 $u = $this->factory->user->create();438 $g = $this->factory->group->create();439 $old_current_user = get_current_user_id();440 $this->set_current_user( $u );441 442 $group = groups_get_group( array(443 'group_id' => $g,444 ) );445 446 $this->go_to( bp_get_group_permalink( $group ) );447 448 $subnav_item = array(449 'user_has_access' => false,450 'no_access_url' => bp_get_group_permalink( $group ),451 );452 453 // Just test relevant info454 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );455 $this->assertSame( 'failure', $found['status'] );456 $this->assertSame( bp_get_group_permalink( $group ), $found['redirect_args']['root'] );457 458 // Clean up459 $this->set_current_user( $old_current_user );460 }461 462 /**463 * @group bp_core_maybe_hook_new_subnav_screen_function464 */465 public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_group_no_redirect_url_provided() {466 $u = $this->factory->user->create();467 $g = $this->factory->group->create();468 $old_current_user = get_current_user_id();469 $this->set_current_user( $u );470 471 $group = groups_get_group( array(472 'group_id' => $g,473 ) );474 475 $this->go_to( bp_get_group_permalink( $group ) );476 477 $subnav_item = array(478 'user_has_access' => false,479 );480 481 // Just test relevant info482 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );483 $this->assertSame( 'failure', $found['status'] );484 $this->assertSame( bp_get_root_domain(), $found['redirect_args']['root'] );485 486 // Clean up487 $this->set_current_user( $old_current_user );488 }489 490 /**491 * @group bp_core_new_subnav_item()492 */493 public function test_bp_core_new_subnav_item_should_trailingslash_link_when_link_is_autogenerated_using_slug() {494 bp_core_new_subnav_item( array(495 'name' => 'bar',496 'slug' => 'bar',497 'parent_slug' => 'foo',498 'parent_url' => bp_get_root_domain() . 'foo/',499 'screen_function' => 'foo',500 ) );501 502 $expected = bp_get_root_domain() . 'foo/bar/';503 $this->assertSame( $expected, buddypress()->bp_options_nav['foo']['bar']['link'] );504 }505 506 /**507 * @group bp_core_new_subnav_item()508 */509 public function test_bp_core_new_subnav_item_should_trailingslash_link_when_link_is_autogenerated_not_using_slug() {510 bp_core_new_nav_item( array(511 'name' => 'foo',512 'slug' => 'foo-parent',513 'link' => bp_get_root_domain() . 'foo-parent/',514 'default_subnav_slug' => 'bar',515 'screen_function' => 'foo',516 ) );517 518 bp_core_new_subnav_item( array(519 'name' => 'bar',520 'slug' => 'bar',521 'parent_slug' => 'foo-parent',522 'parent_url' => bp_get_root_domain() . 'foo-parent/',523 'screen_function' => 'bar',524 ) );525 526 $expected = bp_get_root_domain() . 'foo-parent/';527 $this->assertSame( $expected, buddypress()->bp_options_nav['foo-parent']['bar']['link'] );528 }529 530 /**531 * @group bp_core_new_subnav_item532 * @ticket BP6353533 */534 public function test_bp_core_new_subnav_item_link_should_not_trailingslash_link_explicit_link() {535 $link = 'http://example.com/foo/bar/blah/?action=edit&id=30';536 537 bp_core_new_subnav_item( array(538 'name' => 'bar',539 'slug' => 'bar',540 'parent_slug' => 'foo',541 'parent_url' => 'http://example.com/foo/',542 'screen_function' => 'foo',543 'link' => $link,544 ) );545 546 $this->assertSame( $link, buddypress()->bp_options_nav['foo']['bar']['link'] );547 47 } 548 48
Note: See TracChangeset
for help on using the changeset viewer.