Skip to content

Commit

Permalink
Fix new tests for older WordPress versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Jul 17, 2024
1 parent 754904b commit 8ed28cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/phpunit/tests/Dependencies/Script_Module_Registry_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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' );
Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/tests/Dependencies/Script_Registry_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
}
}

0 comments on commit 8ed28cc

Please sign in to comment.