Skip to content

Commit a80c4a2

Browse files
committed
Added checks for multisite environments in the tests
1 parent b0e1b1b commit a80c4a2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/phpunit/tests/block-supports/wpStripCustomCssFromBlocks.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,20 @@ public function test_filter_added_for_user_without_edit_css() {
160160
*/
161161
public function test_filter_not_added_for_user_with_edit_css() {
162162
$admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
163+
if ( is_multisite() ) {
164+
grant_super_admin( $admin_id );
165+
}
163166
wp_set_current_user( $admin_id );
164167
wp_custom_css_kses_init();
165168

166169
$this->assertFalse( has_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks' ), 'content_save_pre filter should not be added for users with edit_css.' );
167170
$this->assertFalse( has_filter( 'content_filtered_save_pre', 'wp_strip_custom_css_from_blocks' ), 'content_filtered_save_pre filter should not be added for users with edit_css.' );
168171

172+
if ( is_multisite() ) {
173+
revoke_super_admin( $admin_id );
174+
}
169175
wp_set_current_user( 0 );
176+
wp_custom_css_remove_filters();
170177
}
171178

172179
/**
@@ -182,14 +189,23 @@ public function test_filter_not_added_for_user_with_edit_css() {
182189
public function test_set_current_user_action_triggers_reinit() {
183190
$admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
184191
$author_id = self::factory()->user->create( array( 'role' => 'author' ) );
192+
if ( is_multisite() ) {
193+
grant_super_admin( $admin_id );
194+
}
185195

196+
// Switching to a user without edit_css should add the filter via the set_current_user action.
186197
wp_set_current_user( $author_id );
187198
$this->assertNotFalse( has_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks' ), 'Filter should be active for user without edit_css.' );
188199

200+
// Switching to a user with edit_css should remove the filter via the set_current_user action.
189201
wp_set_current_user( $admin_id );
190202
$this->assertFalse( has_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks' ), 'Filter should be removed after switching to a user with edit_css.' );
191203

204+
if ( is_multisite() ) {
205+
revoke_super_admin( $admin_id );
206+
}
192207
wp_set_current_user( 0 );
208+
wp_custom_css_remove_filters();
193209
}
194210

195211
/**
@@ -201,6 +217,9 @@ public function test_set_current_user_action_triggers_reinit() {
201217
*/
202218
public function test_force_filtered_html_on_import_enables_filter_for_privileged_user() {
203219
$admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
220+
if ( is_multisite() ) {
221+
grant_super_admin( $admin_id );
222+
}
204223
wp_set_current_user( $admin_id );
205224
wp_custom_css_kses_init();
206225

@@ -210,6 +229,9 @@ public function test_force_filtered_html_on_import_enables_filter_for_privileged
210229

211230
$this->assertNotFalse( has_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks' ), 'Filter should be enabled during import regardless of user capability.' );
212231

232+
if ( is_multisite() ) {
233+
revoke_super_admin( $admin_id );
234+
}
213235
wp_set_current_user( 0 );
214236
wp_custom_css_remove_filters();
215237
}

0 commit comments

Comments
 (0)