Ticket #39082: 39082.diff
File 39082.diff, 5.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/admin-bar.php
451 451 'title' => __( 'Dashboard' ), 452 452 'href' => network_admin_url(), 453 453 ) ); 454 $wp_admin_bar->add_menu( array( 455 'parent' => 'network-admin', 456 'id' => 'network-admin-s', 457 'title' => __( 'Sites' ), 458 'href' => network_admin_url( 'sites.php' ), 459 ) ); 460 $wp_admin_bar->add_menu( array( 461 'parent' => 'network-admin', 462 'id' => 'network-admin-u', 463 'title' => __( 'Users' ), 464 'href' => network_admin_url( 'users.php' ), 465 ) ); 466 $wp_admin_bar->add_menu( array( 467 'parent' => 'network-admin', 468 'id' => 'network-admin-t', 469 'title' => __( 'Themes' ), 470 'href' => network_admin_url( 'themes.php' ), 471 ) ); 472 $wp_admin_bar->add_menu( array( 473 'parent' => 'network-admin', 474 'id' => 'network-admin-p', 475 'title' => __( 'Plugins' ), 476 'href' => network_admin_url( 'plugins.php' ), 477 ) ); 478 $wp_admin_bar->add_menu( array( 479 'parent' => 'network-admin', 480 'id' => 'network-admin-o', 481 'title' => __( 'Settings' ), 482 'href' => network_admin_url( 'settings.php' ), 483 ) ); 454 455 if ( current_user_can( 'manage_sites' ) ) { 456 $wp_admin_bar->add_menu( array( 457 'parent' => 'network-admin', 458 'id' => 'network-admin-s', 459 'title' => __( 'Sites' ), 460 'href' => network_admin_url( 'sites.php' ), 461 ) ); 462 } 463 464 if ( current_user_can( 'manage_network_users' ) ) { 465 $wp_admin_bar->add_menu( array( 466 'parent' => 'network-admin', 467 'id' => 'network-admin-u', 468 'title' => __( 'Users' ), 469 'href' => network_admin_url( 'users.php' ), 470 ) ); 471 } 472 473 if ( current_user_can( 'manage_network_themes' ) ) { 474 $wp_admin_bar->add_menu( array( 475 'parent' => 'network-admin', 476 'id' => 'network-admin-t', 477 'title' => __( 'Themes' ), 478 'href' => network_admin_url( 'themes.php' ), 479 ) ); 480 } 481 482 if ( current_user_can( 'manage_network_plugins' ) ) { 483 $wp_admin_bar->add_menu( array( 484 'parent' => 'network-admin', 485 'id' => 'network-admin-p', 486 'title' => __( 'Plugins' ), 487 'href' => network_admin_url( 'plugins.php' ), 488 ) ); 489 } 490 491 if ( current_user_can( 'manage_network_options' ) ) { 492 $wp_admin_bar->add_menu( array( 493 'parent' => 'network-admin', 494 'id' => 'network-admin-o', 495 'title' => __( 'Settings' ), 496 'href' => network_admin_url( 'settings.php' ), 497 ) ); 498 } 484 499 } 485 500 486 501 // Add site links -
tests/phpunit/tests/adminbar.php
583 583 $this->assertEquals( $uuid, $query_params['changeset_uuid'] ); 584 584 $this->assertNotContains( 'changeset_uuid', $query_params['url'] ); 585 585 } 586 587 /** 588 * @ticket 39082 589 */ 590 public function test_my_sites_network_menu_for_regular_user() { 591 if ( ! is_multisite() ) { 592 $this->markTestSkipped( 'Test only runs in multisite' ); 593 } 594 595 wp_set_current_user( self::$editor_id ); 596 597 $wp_admin_bar = $this->get_standard_admin_bar(); 598 599 $nodes = $wp_admin_bar->get_nodes(); 600 foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { 601 $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must not display for a regular user.', $id ) ); 602 } 603 } 604 605 /** 606 * @ticket 39082 607 */ 608 public function test_my_sites_network_menu_for_super_admin() { 609 if ( ! is_multisite() ) { 610 $this->markTestSkipped( 'Test only runs in multisite' ); 611 } 612 613 wp_set_current_user( self::$editor_id ); 614 615 grant_super_admin( self::$editor_id ); 616 $wp_admin_bar = $this->get_standard_admin_bar(); 617 revoke_super_admin( self::$editor_id ); 618 619 $nodes = $wp_admin_bar->get_nodes(); 620 foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { 621 $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must display for a super admin.', $id ) ); 622 } 623 } 624 625 /** 626 * @ticket 39082 627 */ 628 public function test_my_sites_network_menu_for_regular_user_with_network_caps() { 629 global $current_user; 630 631 if ( ! is_multisite() ) { 632 $this->markTestSkipped( 'Test only runs in multisite' ); 633 } 634 635 $network_user_caps = array( 'manage_network', 'manage_network_themes', 'manage_network_plugins' ); 636 637 wp_set_current_user( self::$editor_id ); 638 639 foreach ( $network_user_caps as $network_cap ) { 640 $current_user->add_cap( $network_cap ); 641 } 642 $wp_admin_bar = $this->get_standard_admin_bar(); 643 foreach ( $network_user_caps as $network_cap ) { 644 $current_user->remove_cap( $network_cap ); 645 } 646 647 $nodes = $wp_admin_bar->get_nodes(); 648 foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { 649 if ( in_array( $cap, $network_user_caps ) ) { 650 $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); 651 } else { 652 $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); 653 } 654 } 655 } 656 657 private function get_my_sites_network_menu_items() { 658 return array( 659 'my-sites-super-admin' => 'manage_network', 660 'network-admin' => 'manage_network', 661 'network-admin-d' => 'manage_network', 662 'network-admin-s' => 'manage_sites', 663 'network-admin-u' => 'manage_network_users', 664 'network-admin-t' => 'manage_network_themes', 665 'network-admin-p' => 'manage_network_plugins', 666 'network-admin-o' => 'manage_network_options', 667 ); 668 } 586 669 }