From de6f51823a9677d3e15ad4671723c01fd541caaf Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 13 Jul 2023 12:39:42 +0000 Subject: [PATCH] Tests: Add tests to ensure the `contribute` Toolbar node is added when appropriate. Follow-up to [56220]. Props costdev. See #23348. git-svn-id: https://develop.svn.wordpress.org/trunk@56227 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/adminbar.php | 57 +++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index aa8043e7ec..4ca3f64d0d 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -469,7 +469,7 @@ class Tests_AdminBar extends WP_UnitTestCase { * @group ms-required */ public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() { - // User is not a member of a site. + // User is not a member of the site. remove_user_from_blog( self::$no_role_id, get_current_blog_id() ); wp_set_current_user( self::$no_role_id ); @@ -484,6 +484,61 @@ class Tests_AdminBar extends WP_UnitTestCase { $this->assertNotNull( $about_node ); } + /** + * Tests that the 'contribute' node is added for users with a role in single site. + * + * @ticket 23348 + * + * @group ms-excluded + * + * @covers ::wp_admin_bar_wp_menu + */ + public function test_admin_bar_contains_contribute_node_for_users_with_role() { + wp_set_current_user( self::$editor_id ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + + $this->assertNotNull( $wp_admin_bar->get_node( 'contribute' ) ); + } + + /** + * Tests that the 'contribute' node is not added for users with no role in single site. + * + * @ticket 23348 + * + * @group ms-excluded + * + * @covers ::wp_admin_bar_wp_menu + */ + public function test_admin_bar_does_not_contain_contribute_node_for_users_with_no_role() { + wp_set_current_user( self::$no_role_id ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + + $this->assertNull( $wp_admin_bar->get_node( 'contribute' ) ); + } + + /** + * Tests that the 'contribute' node is added for users with no role in multisite. + * + * @ticket 23348 + * + * @group multisite + * @group ms-required + * + * @covers ::wp_admin_bar_wp_menu + */ + public function test_admin_bar_contains_contribute_node_for_users_with_no_role_in_multisite() { + // User is not a member of the site. + remove_user_from_blog( self::$no_role_id, get_current_blog_id() ); + + wp_set_current_user( self::$no_role_id ); + + $wp_admin_bar = $this->get_standard_admin_bar(); + + $this->assertNotNull( $wp_admin_bar->get_node( 'contribute' ) ); + } + /** * @ticket 34113 */