From 8ed28cc02b9c6137691d99a993d5ada4b0842c8b Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 17 Jul 2024 20:45:08 +0200 Subject: [PATCH] Fix new tests for older WordPress versions. --- .../Dependencies/Script_Module_Registry_Tests.php | 14 ++++++++++++++ .../tests/Dependencies/Script_Registry_Tests.php | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/Dependencies/Script_Module_Registry_Tests.php b/tests/phpunit/tests/Dependencies/Script_Module_Registry_Tests.php index 899877b..dd144ce 100644 --- a/tests/phpunit/tests/Dependencies/Script_Module_Registry_Tests.php +++ b/tests/phpunit/tests/Dependencies/Script_Module_Registry_Tests.php @@ -150,6 +150,13 @@ public function test_get_all_registered() { } public function test_enqueue() { + // Script modules are only supported in WordPress 6.5 and later. + if ( version_compare( $GLOBALS['wp_version'], '6.5', '<' ) ) { + $this->expectDoingItWrong( Script_Module_Registry::class . '::enqueue' ); + $this->assertFalse( $this->registry->enqueue( 'test_script_module' ) ); + return; + } + wp_register_script_module( 'test_script_module', 'test-script-module.js' ); $registered = $this->get_hidden_property_value( wp_script_modules(), 'registered' ); @@ -162,6 +169,13 @@ public function test_enqueue() { } public function test_dequeue() { + // Script modules are only supported in WordPress 6.5 and later. + if ( version_compare( $GLOBALS['wp_version'], '6.5', '<' ) ) { + $this->expectDoingItWrong( Script_Module_Registry::class . '::dequeue' ); + $this->assertFalse( $this->registry->dequeue( 'test_script_module' ) ); + return; + } + wp_enqueue_script_module( 'test_script_module', 'test-script-module.js' ); $registered = $this->get_hidden_property_value( wp_script_modules(), 'registered' ); diff --git a/tests/phpunit/tests/Dependencies/Script_Registry_Tests.php b/tests/phpunit/tests/Dependencies/Script_Registry_Tests.php index c0a1763..d3517a6 100644 --- a/tests/phpunit/tests/Dependencies/Script_Registry_Tests.php +++ b/tests/phpunit/tests/Dependencies/Script_Registry_Tests.php @@ -203,6 +203,10 @@ public function test_add_inline_code() { wp_enqueue_script( 'test_script', 'test-script.js' ); $this->registry->add_inline_code( 'test_script', $js ); - $this->assertSame( $js, wp_scripts()->get_inline_script_data( 'test_script' ) ); + if ( ! method_exists( wp_scripts(), 'get_inline_script_data' ) ) { + $this->assertSame( array( $js ), wp_scripts()->get_data( 'test_script', 'after' ) ); + } else { + $this->assertSame( $js, wp_scripts()->get_inline_script_data( 'test_script' ) ); + } } }