@@ -23,6 +23,8 @@ class Branding_AddAdminBarMenuTest extends WP_UnitTestCase {
2323 * Test that the main admin bar menu is added.
2424 */
2525 public function test_should_add_main_admin_bar_menu () {
26+ $ this ->set_user_to_administrator ();
27+
2628 $ wp_admin_bar = new WP_Admin_Bar ();
2729 $ branding = new AspireUpdate \Branding ();
2830
@@ -43,6 +45,8 @@ public function test_should_add_main_admin_bar_menu() {
4345 * Test that the status menu item is added.
4446 */
4547 public function test_should_add_status_menu_item () {
48+ $ this ->set_user_to_administrator ();
49+
4650 $ wp_admin_bar = new WP_Admin_Bar ();
4751 $ branding = new AspireUpdate \Branding ();
4852
@@ -72,9 +76,11 @@ public function test_should_add_status_menu_item() {
7276 }
7377
7478 /**
75- * Test that the settings link is not added when the user lacks appropriate capabilities .
79+ * Test that the settings link is added.
7680 */
77- public function test_should_not_add_settings_link_when_the_user_lacks_appropriate_capabilities () {
81+ public function test_should_add_settings_link () {
82+ $ this ->set_user_to_administrator ();
83+
7884 $ wp_admin_bar = new WP_Admin_Bar ();
7985 $ branding = new AspireUpdate \Branding ();
8086
@@ -84,24 +90,17 @@ public function test_should_not_add_settings_link_when_the_user_lacks_appropriat
8490 $ actual = $ wp_admin_bar ->get_nodes ();
8591
8692 $ this ->assertIsArray ( $ actual , 'There are no admin bar nodes. ' );
87- $ this ->assertArrayNotHasKey (
93+ $ this ->assertArrayHasKey (
8894 'aspireupdate-admin-bar-menu-settings ' ,
8995 $ actual ,
90- 'The settings link is present. '
96+ 'The settings link is not present. '
9197 );
9298 }
9399
94100 /**
95- * Test that the settings link is added when the user has appropriate capabilities.
101+ * Test that the main admin bar menu is not added when the user lacks appropriate capabilities.
96102 */
97- public function test_should_add_settings_link_when_the_user_has_appropriate_capabilities () {
98- $ user = $ this ->factory ->user ->create ( [ 'role ' => 'administrator ' ] );
99- wp_set_current_user ( $ user );
100-
101- if ( is_multisite () ) {
102- grant_super_admin ( $ user );
103- }
104-
103+ public function test_should_not_add_main_admin_bar_menu_when_the_user_lacks_appropriate_capabilities () {
105104 $ wp_admin_bar = new WP_Admin_Bar ();
106105 $ branding = new AspireUpdate \Branding ();
107106
@@ -110,23 +109,17 @@ public function test_should_add_settings_link_when_the_user_has_appropriate_capa
110109
111110 $ actual = $ wp_admin_bar ->get_nodes ();
112111
113- $ this ->assertIsArray ( $ actual , 'There are no admin bar nodes. ' );
114- $ this ->assertArrayHasKey (
115- 'aspireupdate-admin-bar-menu-settings ' ,
116- $ actual ,
117- 'The settings link is not present. '
118- );
112+ $ this ->assertIsNotArray ( $ actual , 'There are admin bar nodes. ' );
119113 }
120114
121115 /**
122- * Test that the menu is not added when AP_REMOVE_UI is set to true.
116+ * Test that the main admin bar menu is not added when AP_REMOVE_UI is set to true.
123117 */
124- public function test_should_not_enqueue_style_when_ap_remove_ui_is_true () {
118+ public function test_should_not_add_main_admin_bar_menu_when_ap_remove_ui_is_true () {
125119 // Prevent the menu from being added.
126120 define ( 'AP_REMOVE_UI ' , true );
127121
128- $ user = $ this ->factory ->user ->create ( [ 'role ' => 'administrator ' ] );
129- wp_set_current_user ( $ user );
122+ $ this ->set_user_to_administrator ();
130123
131124 $ wp_admin_bar = new WP_Admin_Bar ();
132125 $ branding = new AspireUpdate \Branding ();
@@ -150,6 +143,8 @@ public function test_should_not_enqueue_style_when_ap_remove_ui_is_true() {
150143 public function test_should_set_status_menu_item_content_depending_on_the_api_host_option ( $ api_host , $ expected_name ) {
151144 define ( 'AP_HOST ' , $ api_host );
152145
146+ $ this ->set_user_to_administrator ();
147+
153148 $ wp_admin_bar = new WP_Admin_Bar ();
154149 $ branding = new AspireUpdate \Branding ();
155150
@@ -205,4 +200,20 @@ public function data_api_hosts_and_expected_names() {
205200 ],
206201 ];
207202 }
203+
204+ /**
205+ * Set the current user to an administrator.
206+ *
207+ * Grants super admin privileges when running multisite.
208+ *
209+ * @return void
210+ */
211+ private function set_user_to_administrator () {
212+ $ user = $ this ->factory ->user ->create ( [ 'role ' => 'administrator ' ] );
213+ wp_set_current_user ( $ user );
214+
215+ if ( is_multisite () ) {
216+ grant_super_admin ( $ user );
217+ }
218+ }
208219}
0 commit comments