Skip to content

Commit 0a700cd

Browse files
committed
Unit tests: Update tests to handle deprecation of core's print_inline_script()
1 parent ba03ba4 commit 0a700cd

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
* New: Add tests to verify filtered values output nothing when empty
6868
* New: Add test to check that the appropriate number of framework strings are translatable
6969
* Change: In bootstrap, add backcompat for PHPUnit pre-v6.0
70+
* Fix: Update tests to handle deprecation of core's `print_inline_script()`
7071
* Change: Update copyright date (2025)
7172
* Change: Reduce number of tags defined in readme.txt
7273

‎tests/phpunit/tests/add-admin-css.php‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,27 +659,42 @@ public function test_add_codemirror_adds_scripts() {
659659
$this->fake_current_screen();
660660
$this->obj->add_codemirror();
661661

662-
$expected = 'jQuery\.extend\( wp\.codeEditor\.defaultSettings, {"codemirror":.+wp\.codeEditor\.initialize\( "css".+\);';
662+
$expected = 'jQuery\.extend\( wp\.codeEditor\.defaultSettings, {"codemirror":';
663663

664-
$this->expectOutputRegex( '~' . $expected . '~ims', wp_scripts()->print_inline_script( 'code-editor' ) );
664+
if ( method_exists( 'WP_Scripts', 'get_inline_script_data' ) ) {
665+
$this->assertMatchesRegularExpression( '~' . $expected . '~ims', wp_scripts()->get_inline_script_data( 'code-editor' ) );
666+
} else {
667+
// Pre WP-6.3
668+
$this->expectOutputRegex( '~' . $expected . '~ims', wp_scripts()->print_inline_script( 'code-editor' ) );
669+
}
665670
}
666671

667672
public function test_add_codemirror_does_not_add_scripts_on_other_screen_ids() {
668673
$this->fake_current_screen();
669674
set_current_screen( 'another' );
670675
$this->obj->add_codemirror();
671676

672-
$inline_script = wp_scripts()->print_inline_script( 'code-editor', 'after', false );
677+
if ( method_exists( 'WP_Scripts', 'get_inline_script_data' ) ) {
678+
$inline_script = wp_scripts()->get_inline_script_data( 'code-editor' );
679+
} else {
680+
// Pre WP-6.3
681+
$inline_script = wp_scripts()->print_inline_script( 'code-editor', 'after', false );
682+
}
673683

674-
$this->assertEquals( '', $inline_script );
684+
$this->assertEmpty( $inline_script );
675685
}
676686

677687
public function test_add_codemirror_does_not_add_scripts_if_code_editor_not_registered() {
678688
$this->fake_current_screen();
679689
wp_deregister_script( 'code-editor' );
680690
$this->obj->add_codemirror();
681691

682-
$inline_script = wp_scripts()->print_inline_script( 'code-editor', 'after', false );
692+
if ( method_exists( 'WP_Scripts', 'get_inline_script_data' ) ) {
693+
$inline_script = wp_scripts()->get_inline_script_data( 'code-editor' );
694+
} else {
695+
// Pre WP-6.3
696+
$inline_script = wp_scripts()->print_inline_script( 'code-editor', 'after', false );
697+
}
683698

684699
$this->assertEmpty( $inline_script );
685700
}

0 commit comments

Comments
 (0)