11
11
* @covers \AspireUpdate\Admin_Settings::admin_notices
12
12
*/
13
13
class AdminSettings_AdminNoticesTest extends AdminSettings_UnitTestCase {
14
+ /**
15
+ * Test that the reset notice is not output when the user does not have the required capability.
16
+ */
17
+ public function test_should_not_output_reset_notice_when_the_user_does_not_have_the_required_capability () {
18
+ wp_set_current_user ( self ::$ editor_id );
19
+
20
+ $ this ->assertFalse (
21
+ current_user_can ( is_multisite () ? 'manage_network_options ' : 'manage_options ' ),
22
+ 'The user has the required capability. '
23
+ );
24
+
25
+ update_site_option ( 'aspireupdate-reset ' , 'true ' );
26
+ $ _GET ['reset-success ' ] = 'success ' ;
27
+ $ _GET ['reset-success-nonce ' ] = wp_create_nonce ( 'aspireupdate-reset-success-nonce ' );
28
+
29
+ $ admin_settings = new \AspireUpdate \Admin_Settings ();
30
+ $ actual = get_echo ( [ $ admin_settings , 'admin_notices ' ] );
31
+
32
+ unset( $ _GET ['reset-success ' ], $ _GET ['reset-success-nonce ' ] );
33
+
34
+ $ this ->assertEmpty ( $ actual );
35
+ }
36
+
14
37
/**
15
38
* Test that the reset notice is not output when the 'aspireupdate-reset' option is not set to (string) "true".
16
39
*/
@@ -104,6 +127,10 @@ public function test_should_output_reset_notice() {
104
127
$ _GET ['reset-success ' ] = 'success ' ;
105
128
$ _GET ['reset-success-nonce ' ] = wp_create_nonce ( 'aspireupdate-reset-success-nonce ' );
106
129
130
+ if ( is_multisite () ) {
131
+ grant_super_admin ( wp_get_current_user ()->ID );
132
+ }
133
+
107
134
$ admin_settings = new \AspireUpdate \Admin_Settings ();
108
135
$ actual = get_echo ( [ $ admin_settings , 'admin_notices ' ] );
109
136
@@ -123,6 +150,10 @@ public function test_should_delete_aspireupdatereset_option_after_output() {
123
150
$ _GET ['reset-success ' ] = 'success ' ;
124
151
$ _GET ['reset-success-nonce ' ] = wp_create_nonce ( 'aspireupdate-reset-success-nonce ' );
125
152
153
+ if ( is_multisite () ) {
154
+ grant_super_admin ( wp_get_current_user ()->ID );
155
+ }
156
+
126
157
$ admin_settings = new \AspireUpdate \Admin_Settings ();
127
158
get_echo ( [ $ admin_settings , 'admin_notices ' ] );
128
159
@@ -163,6 +194,10 @@ public function test_should_not_output_saved_notice_when_nonce_verification_fail
163
194
public function test_should_output_saved_notice () {
164
195
$ _GET ['settings-updated-wpnonce ' ] = wp_create_nonce ( 'aspireupdate-settings-updated-nonce ' );
165
196
197
+ if ( is_multisite () ) {
198
+ grant_super_admin ( wp_get_current_user ()->ID );
199
+ }
200
+
166
201
$ admin_settings = new \AspireUpdate \Admin_Settings ();
167
202
$ actual = get_echo ( [ $ admin_settings , 'admin_notices ' ] );
168
203
0 commit comments