Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dbcd32c
Output script modules with fetchpriority=low
westonruter May 19, 2025
5207c27
Fix duplicate array keys in data_special_chars_script_encoding
westonruter May 19, 2025
088366d
Add ability to set fetch priority for script modules
westonruter May 19, 2025
9eab85d
Add fetchpriority support for non-module scripts
westonruter May 19, 2025
d9c4037
Set fetchpriority=low on comment-reply script
westonruter May 19, 2025
4f82a4f
Use auto as default fetchpriority for script modules
westonruter May 19, 2025
f2cd9be
Avoid printing fetchpriority attribute when auto
westonruter May 19, 2025
ff4fd36
fixup! Use auto as default fetchpriority for script modules
westonruter May 19, 2025
9edbe4c
Use HTML Tag Processor to parse import map
westonruter May 19, 2025
021fe74
Ensure parity in args between class methods and global function aliases
westonruter May 19, 2025
34ef7fa
Use fetch priority low by default for Interactivity API view script m…
westonruter May 20, 2025
e54274a
Add missing since tag
westonruter May 21, 2025
cc1d909
Account for full block.json schema when checking for interactivity
westonruter May 21, 2025
4197eb2
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Jun 20, 2025
74a49e1
Remove PHPStan annotations for commit
westonruter Jun 20, 2025
75fb879
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Jul 29, 2025
0e9994a
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Aug 26, 2025
06e9cac
Remove TODO comments which have been filed in https://github.com/Word…
westonruter Aug 26, 2025
f91c61d
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Sep 1, 2025
4596644
Add validation for fetchpriority set on scripts
westonruter Sep 2, 2025
2172e9e
Allow empty string for set_fetchpriority(), return bool, and add tests
westonruter Sep 2, 2025
535669d
Add missing type for args param
westonruter Sep 2, 2025
fe366e2
Improve typing for is_delayed_stragegy
westonruter Sep 2, 2025
f704f5e
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Sep 2, 2025
38150dc
Replace n.e.x.t with 6.9.0
westonruter Sep 2, 2025
f05ca72
Ensure reflection property is accessible
westonruter Sep 2, 2025
607ce0c
Use static data provider methods
westonruter Sep 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ensure reflection property is accessible
  • Loading branch information
westonruter committed Sep 2, 2025
commit f05ca7218405f0ea97ad58828e0183893e6ee0ec
34 changes: 19 additions & 15 deletions tests/phpunit/tests/script-modules/wpScriptModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1279,20 +1279,17 @@ public function data_provider_fetchpriority_values(): array {
* @param string $fetchpriority The fetchpriority value to test.
*/
public function test_fetchpriority_values( string $fetchpriority ) {
$reflection_class = new ReflectionClass( $this->script_modules );
$registered_property = $reflection_class->getProperty( 'registered' );

$this->script_modules->register( 'test-script', '/test-script.js', array(), null, array( 'fetchpriority' => $fetchpriority ) );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( $fetchpriority, $registered_modules['test-script']['fetchpriority'] );

$this->script_modules->register( 'test-script-2', '/test-script-2.js' );
$this->assertTrue( $this->script_modules->set_fetchpriority( 'test-script-2', $fetchpriority ) );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( $fetchpriority, $registered_modules['test-script-2']['fetchpriority'] );

$this->assertTrue( $this->script_modules->set_fetchpriority( 'test-script-2', '' ) );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( 'auto', $registered_modules['test-script-2']['fetchpriority'] );
}

Expand All @@ -1306,9 +1303,7 @@ public function test_fetchpriority_values( string $fetchpriority ) {
*/
public function test_register_script_module_having_fetchpriority_with_invalid_value() {
$this->script_modules->register( 'foo', '/foo.js', array(), false, array( 'fetchpriority' => 'silly' ) );
$reflection_class = new ReflectionClass( $this->script_modules );
$registered_property = $reflection_class->getProperty( 'registered' );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( 'auto', $registered_modules['foo']['fetchpriority'] );
$this->assertArrayHasKey( 'WP_Script_Modules::register', $this->caught_doing_it_wrong );
$this->assertStringContainsString( 'Invalid fetchpriority `silly`', $this->caught_doing_it_wrong['WP_Script_Modules::register'] );
Expand All @@ -1324,9 +1319,7 @@ public function test_register_script_module_having_fetchpriority_with_invalid_va
*/
public function test_register_script_module_having_fetchpriority_with_invalid_value_type() {
$this->script_modules->register( 'foo', '/foo.js', array(), false, array( 'fetchpriority' => array( 'WHY AM I NOT A STRING???' ) ) );
$reflection_class = new ReflectionClass( $this->script_modules );
$registered_property = $reflection_class->getProperty( 'registered' );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( 'auto', $registered_modules['foo']['fetchpriority'] );
$this->assertArrayHasKey( 'WP_Script_Modules::register', $this->caught_doing_it_wrong );
$this->assertStringContainsString( 'Invalid fetchpriority `array`', $this->caught_doing_it_wrong['WP_Script_Modules::register'] );
Expand All @@ -1344,12 +1337,23 @@ public function test_register_script_module_having_fetchpriority_with_invalid_va
public function test_set_fetchpriority_with_invalid_value() {
$this->script_modules->register( 'foo', '/foo.js' );
$this->script_modules->set_fetchpriority( 'foo', 'silly' );
$reflection_class = new ReflectionClass( $this->script_modules );
$registered_property = $reflection_class->getProperty( 'registered' );
$registered_modules = $registered_property->getValue( $this->script_modules );
$registered_modules = $this->get_registered_script_modules( $this->script_modules );
$this->assertSame( 'auto', $registered_modules['foo']['fetchpriority'] );
}

/**
* Gets registered script modules.
*
* @param WP_Script_Modules $script_modules
* @return array<string, array> Registered modules.
*/
private function get_registered_script_modules( WP_Script_Modules $script_modules ): array {
$reflection_class = new ReflectionClass( $script_modules );
$registered_property = $reflection_class->getProperty( 'registered' );
$registered_property->setAccessible( true );
return $registered_property->getValue( $script_modules );
}
Comment on lines +1350 to +1355
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to do some work on https://core.trac.wordpress.org/ticket/60597 to open modules and not require reflection 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It would be nice if there were more getters and setters, similar to WP_Scripts.


/**
* Data provider.
*
Expand Down
Loading