-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathEnqueueAdminTest.php
More file actions
618 lines (482 loc) · 20.9 KB
/
Copy pathEnqueueAdminTest.php
File metadata and controls
618 lines (482 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<?php
/**
* Test cases for the Enqueue_Admin class.
*
* @package accessibility-checker
*/
use EDAC\Admin\Enqueue_Admin;
/**
* Tests for functionality of the Enqueue_Admin class.
*/
class EnqueueAdminTest extends WP_UnitTestCase {
/**
* Holds the instance of the Enqueue_Admin class.
*
* @var Enqueue_Admin the instance of the Enqueue_Admin class.
*/
private $enqueue_admin;
/**
* Holds the test admin user ID.
*
* @var int
*/
private $test_admin_user_id;
/**
* Setup the option, global wp_scripts and the Enqueue_Admin instance.
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$this->test_admin_user_id = self::factory()->user->create(
[
'role' => 'administrator',
]
);
wp_set_current_user( $this->test_admin_user_id );
update_option( 'edac_post_types', [ 'post', 'page' ] );
global $wp_scripts, $wp_styles;
$wp_scripts = new \WP_Scripts();
$wp_styles = new \WP_Styles();
$this->enqueue_admin = new Enqueue_Admin();
}
/**
* Clean up the option, global wp_scripts and the Enqueue_Admin instance.
*
* @return void
*/
protected function tearDown(): void {
if ( $this->test_admin_user_id ) {
delete_user_meta( $this->test_admin_user_id, 'show_sr_text_in_editor' );
}
wp_set_current_user( 0 );
if ( $this->test_admin_user_id ) {
wp_delete_user( $this->test_admin_user_id );
$this->test_admin_user_id = 0;
}
parent::tearDown();
delete_option( 'edac_post_types' );
global $wp_scripts, $wp_styles;
unset( $wp_scripts, $wp_styles, $GLOBALS['current_screen'] );
unset( $this->enqueue_admin );
}
/**
* Test that the base script is enqueued in the admin on non-editor pages.
*
* @return void
*/
public function testEnqueueBaseScriptInAdminNonEditorPage() {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$this->assertTrue( wp_script_is( 'edac', 'enqueued' ) );
$this->assertFalse( wp_script_is( 'edac-editor-app', 'enqueued' ) );
$localized_data = $wp_scripts->get_data( 'edac', 'data' );
$this->assertIsString( $localized_data );
$this->assertStringContainsString( 'utm_content=__name__', $localized_data );
$this->assertStringNotContainsString( 'utm-content=__name__', $localized_data );
}
/**
* Test localized pro URL includes the expected underscore UTM content key.
*
* @return void
*/
public function testLocalizedProUrlUsesUnderscoreUtmContentKey() {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$this->assertStringContainsString( 'utm_content=__name__', $localized_data );
$this->assertStringNotContainsString( 'utm-content=__name__', $localized_data );
}
/**
* FixesRestUrl is present in the edac_script_vars localized to the admin script.
*/
public function testLocalizedAdminDataIncludesFixesRestUrl(): void {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$this->assertNotEmpty( $localized_data );
$this->assertStringContainsString( 'fixesRestUrl', $localized_data );
}
/**
* The pro flag in edac_script_vars reflects defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID,
* so non-editor admin pages (e.g. the Issues Explorer) can gate pro-only UI without
* relying on window.edac_editor_app, which is only localized on post.php/post-new.php.
*/
public function testLocalizedAdminDataIncludesProFlag(): void {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$expected_pro = defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID;
// wp_localize_script() stringifies booleans as "1" / "" (matching the
// === '1' checks on the JS side), not JSON true/false.
$this->assertStringContainsString( '"pro"', $localized_data );
$this->assertMatchesRegularExpression(
'/"pro"\s*:\s*"' . ( $expected_pro ? '1' : '' ) . '"/',
$localized_data
);
}
/**
* FixesRestUrl uses the accessibility-checker/v1 namespace and matches rest_url().
*/
public function testAdminFixesRestUrlUsesAccessibilityCheckerV1Namespace(): void {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$expected = esc_url_raw( rest_url( 'accessibility-checker/v1' ) );
$this->assertStringContainsString( '"fixesRestUrl":"' . $expected . '"', str_replace( '\/', '/', $localized_data ) );
}
/**
* FixesRestUrl must be an absolute URL — a root-relative /wp-json path would break
* subdomain multisite installs by resolving to the main site instead of the subsite.
*/
public function testAdminFixesRestUrlIsAbsolute(): void {
global $wp_scripts;
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$this->assertDoesNotMatchRegularExpression( '/"fixesRestUrl"\s*:\s*"\\\\?\/wp-json/', $localized_data );
$this->assertMatchesRegularExpression( '/"fixesRestUrl"\s*:\s*"https?/', $localized_data );
}
/**
* FixesRestUrl in edac_script_vars must follow a custom REST base prefix set via
* the rest_url_prefix filter. Verifies the URL is built with rest_url() rather than
* a hardcoded /wp-json/ string.
* Pretty permalinks are required for the prefix filter to be applied.
*/
public function testAdminFixesRestUrlRespectsCustomRestPrefix(): void {
global $wp_scripts;
update_option( 'permalink_structure', '/%postname%/' );
flush_rewrite_rules(); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules
$prefix_callback = static fn() => 'custom-api';
add_filter( 'rest_url_prefix', $prefix_callback );
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$expected = esc_url_raw( rest_url( 'accessibility-checker/v1' ) );
remove_filter( 'rest_url_prefix', $prefix_callback );
delete_option( 'permalink_structure' );
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
$this->assertStringContainsString( '"fixesRestUrl":"' . $expected . '"', str_replace( '\/', '/', $localized_data ) );
$this->assertStringNotContainsString( 'wp-json', $localized_data );
}
/**
* Test that the base script and editor script is enqueued in the editor for an existing page.
*
* @return void
*/
public function testEnqueueBaseAndEditorScriptsInAdminEditorExisting() {
global $post;
$post = $this->factory()->post->create_and_get();
global $pagenow;
$pagenow = 'post.php';
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$this->assertTrue( wp_script_is( 'edac', 'enqueued' ) );
$this->assertTrue( wp_script_is( 'edac-editor-app', 'enqueued' ) );
}
/**
* Test that the base script and editor script is enqueued in the editor for a new page.
*
* @return void
*/
public function testEnqueueBaseAndEditorScriptsInAdminEditorNew() {
global $post;
$post = $this->factory()->post->create_and_get();
global $pagenow;
$pagenow = 'post-new.php';
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$this->assertTrue( wp_script_is( 'edac', 'enqueued' ) );
$this->assertTrue( wp_script_is( 'edac-editor-app', 'enqueued' ) );
}
/**
* Test that scanUrl uses permalink for frontpage.
*
* @return void
*/
public function testScanUrlUsesPermalinkForFrontpage() {
global $post, $pagenow, $wp_scripts;
// Create a post and set it as the frontpage.
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] );
update_option( 'page_on_front', $post->ID );
$pagenow = 'post.php';
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
// In WP 6.9 there were changes to the flags passed to wp_json_encode() that made slashes no longer get escaped by default.
// We should check for both possibilities here to ensure compatibility across versions.
// See: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
$this->assertStringContainsString( esc_url_raw( get_permalink( $post->ID ) ), $localized_data );
} else {
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
}
$this->assertStringNotContainsString( 'preview=true', $localized_data );
// Cleanup.
delete_option( 'page_on_front' );
}
/**
* Test that scanUrl uses permalink for posts page.
*
* @return void
*/
public function testScanUrlUsesPermalinkForPostsPage() {
global $post, $pagenow, $wp_scripts;
// Create a post and set it as the posts page.
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] );
update_option( 'page_for_posts', $post->ID );
$pagenow = 'post.php';
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
// In WP 6.9 there were changes to the flags passed to wp_json_encode() that made slashes no longer get escaped by default.
// We should check for both possibilities here to ensure compatibility across versions.
// See: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
$this->assertStringContainsString( esc_url_raw( get_permalink( $post->ID ) ), $localized_data );
} else {
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
}
$this->assertStringNotContainsString( 'preview=true', $localized_data );
// Cleanup.
delete_option( 'page_for_posts' );
}
/**
* Test that scanUrl uses preview link for regular posts.
*
* @return void
*/
public function testScanUrlUsesPreviewLinkForRegularPost() {
global $post, $pagenow, $wp_scripts;
// Create a regular post (not frontpage or posts page).
$post = $this->factory()->post->create_and_get();
$pagenow = 'post.php';
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
$this->assertStringContainsString( 'preview=true', $localized_data );
}
/**
* Test that the sidebar assets enqueue only in the block editor for scannable post types.
*/
public function testSidebarScriptEnqueuesInBlockEditorForScannablePost() {
global $post, $pagenow;
$post = $this->factory()->post->create_and_get();
$pagenow = 'post.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sidebar_script();
$this->assertTrue( wp_script_is( 'edac-sidebar', 'enqueued' ) );
$this->assertTrue( wp_style_is( 'edac-sidebar', 'enqueued' ) );
}
/**
* Test that the sidebar assets do not enqueue when not in the block editor.
*/
public function testSidebarScriptDoesNotEnqueueInClassicEditor() {
global $post, $pagenow;
$post = $this->factory()->post->create_and_get();
$pagenow = 'post.php';
$this->set_mock_screen( false );
Enqueue_Admin::maybe_enqueue_sidebar_script();
$this->assertFalse( wp_script_is( 'edac-sidebar', 'enqueued' ) );
$this->assertFalse( wp_style_is( 'edac-sidebar', 'enqueued' ) );
}
/**
* Test that the sidebar assets do not enqueue for non-scannable post types.
*/
public function testSidebarScriptDoesNotEnqueueForNonScannablePostType() {
update_option( 'edac_post_types', [ 'page' ] );
global $post, $pagenow;
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'post' ] );
$pagenow = 'post.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sidebar_script();
$this->assertFalse( wp_script_is( 'edac-sidebar', 'enqueued' ) );
$this->assertFalse( wp_style_is( 'edac-sidebar', 'enqueued' ) );
}
/**
* Test that the sr-only format script enqueues on post.php for a scannable post type.
*/
public function testSrOnlyFormatEnqueuesOnPostEditor() {
global $post, $pagenow;
$post = $this->factory()->post->create_and_get();
$pagenow = 'post.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertTrue( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that the sr-only format script enqueues on post-new.php for a scannable post type.
*/
public function testSrOnlyFormatEnqueuesOnPostNewEditor() {
global $post, $pagenow;
$post = $this->factory()->post->create_and_get();
$pagenow = 'post-new.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertTrue( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that the sr-only format script does not enqueue on post.php for a non-scannable post type.
*/
public function testSrOnlyFormatDoesNotEnqueueForNonScannablePostType() {
update_option( 'edac_post_types', [ 'page' ] );
global $post, $pagenow;
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'post' ] );
$pagenow = 'post.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertFalse( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that the sr-only format script enqueues on the Full Site Editor.
*/
public function testSrOnlyFormatEnqueuesInFullSiteEditor() {
global $pagenow;
$pagenow = 'site-editor.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertTrue( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that the sr-only format script does not enqueue on site-editor.php when not in block editor.
*/
public function testSrOnlyFormatDoesNotEnqueueInFseWhenNotBlockEditor() {
global $pagenow;
$pagenow = 'site-editor.php';
$this->set_mock_screen( false );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertFalse( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that the sr-only format script does not enqueue on unrelated admin pages.
*/
public function testSrOnlyFormatDoesNotEnqueueOnOtherAdminPages() {
global $pagenow;
$pagenow = 'edit.php';
$this->set_mock_screen( true );
Enqueue_Admin::maybe_enqueue_sr_only_format();
$this->assertFalse( wp_script_is( 'edac-sr-only-format', 'enqueued' ) );
}
/**
* Test that edac_filter_admin_post_id overrides the post ID localized into edac_script_vars.
*
* @return void
*/
public function testAdminPostIdFilterOverridesLocalizedPostId() {
global $post, $pagenow, $wp_scripts;
$original_post = $this->factory()->post->create_and_get();
$alternate_post = $this->factory()->post->create_and_get();
$post = $original_post;
$pagenow = 'post.php';
$filter_callback = static function () use ( $alternate_post ) {
return $alternate_post->ID;
};
add_filter( 'edac_filter_admin_post_id', $filter_callback );
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
remove_filter( 'edac_filter_admin_post_id', $filter_callback );
$localized_data = $wp_scripts->get_data( 'edac', 'data' );
$this->assertStringContainsString( (string) $alternate_post->ID, $localized_data );
}
/**
* When the filter flags a latest-posts homepage (show_on_front=posts), the scan URL
* uses get_home_url() rather than an invalid preview link.
*
* @return void
*/
public function testScanUrlUsesHomeUrlWhenLatestPostsHomeFilterReturnsTrue() {
global $post, $pagenow, $wp_scripts;
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] );
$pagenow = 'post.php';
update_option( 'show_on_front', 'posts' );
update_option( 'page_for_posts', 0 );
$filter_callback = static function () {
return true;
};
add_filter( 'edac_filter_post_is_latest_posts_home', $filter_callback );
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
remove_filter( 'edac_filter_post_is_latest_posts_home', $filter_callback );
delete_option( 'show_on_front' );
delete_option( 'page_for_posts' );
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
$this->assertStringNotContainsString( 'preview=true', $localized_data );
// The scan URL should be based on the home URL, not a preview link.
// In WP 6.9 forward slashes are no longer escaped in json_encode output; handle both forms.
// See: https://github.com/WordPress/wordpress-develop/pull/9557.
$expected_home = esc_url_raw( trailingslashit( get_home_url() ) );
if ( version_compare( get_bloginfo( 'version' ), '6.9', '<' ) ) {
$expected_home = str_replace( '/', '\\/', $expected_home );
}
$this->assertStringContainsString( $expected_home, $localized_data );
}
/**
* Fallback case: show_on_front=page with no static front page configured also
* counts as a latest-posts homepage, so the scan URL still uses get_home_url().
*
* @return void
*/
public function testScanUrlUsesHomeUrlWhenShowOnFrontIsPageWithNoFrontPageConfigured() {
global $post, $pagenow, $wp_scripts;
$post = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] );
$pagenow = 'post.php';
update_option( 'show_on_front', 'page' );
delete_option( 'page_on_front' ); // No static front page configured — WP falls back to latest posts.
$filter_callback = static function () {
return true;
};
add_filter( 'edac_filter_post_is_latest_posts_home', $filter_callback );
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
remove_filter( 'edac_filter_post_is_latest_posts_home', $filter_callback );
delete_option( 'show_on_front' );
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
$this->assertStringNotContainsString( 'preview=true', $localized_data );
// The scan URL should be based on the home URL, not a preview link.
// In WP 6.9 forward slashes are no longer escaped in json_encode output; handle both forms.
// See: https://github.com/WordPress/wordpress-develop/pull/9557.
$expected_home = esc_url_raw( trailingslashit( get_home_url() ) );
if ( version_compare( get_bloginfo( 'version' ), '6.9', '<' ) ) {
$expected_home = str_replace( '/', '\\/', $expected_home );
}
$this->assertStringContainsString( $expected_home, $localized_data );
}
/**
* The 'active' flag must reflect the filtered post ID's type: when the filter returns a
* non-scannable post type, $active is false so the scanner doesn't run.
*
* @return void
*/
public function testActiveReflectsFilteredPostIdPostType() {
global $post, $pagenow, $wp_scripts;
// Global $post is a 'post' type (scannable under current option).
$scannable_post = $this->factory()->post->create_and_get( [ 'post_type' => 'post' ] );
// The filter will return a 'page' ID; make 'page' non-scannable for this test.
$non_scannable_post = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] );
$post = $scannable_post;
$pagenow = 'post.php';
// Restrict scannable types to 'post' only so 'page' becomes non-scannable.
update_option( 'edac_post_types', [ 'post' ] );
$filter_callback = static function () use ( $non_scannable_post ) {
return $non_scannable_post->ID;
};
add_filter( 'edac_filter_admin_post_id', $filter_callback );
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
remove_filter( 'edac_filter_admin_post_id', $filter_callback );
// Restore original scannable post types.
update_option( 'edac_post_types', [ 'post', 'page' ] );
$localized_data = $wp_scripts->get_data( 'edac-editor-app', 'data' );
$this->assertNotEmpty( $localized_data );
// $active must be false because the filtered post type ('page') is not scannable.
// wp_localize_script serializes PHP false as "" (empty string) in older WP versions
// and may serialize it as JSON false in newer ones — accept both forms.
$this->assertMatchesRegularExpression( '/"active"\s*:\s*(false|"")/', $localized_data );
}
/**
* Helper to set a mock current screen with block editor context.
*
* @param bool $is_block_editor Whether the screen should behave as block editor.
*/
private function set_mock_screen( bool $is_block_editor ): void {
// As of WP 7.0, get_current_screen() requires an actual WP_Screen
// instance. Use WP_Screen::get() to obtain one without the side effects
// of set_current_screen() (e.g. setting $hook_suffix, $typenow, firing
// the current_screen action).
$GLOBALS['current_screen'] = WP_Screen::get( 'post' );
$GLOBALS['current_screen']->is_block_editor = $is_block_editor;
}
}