Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Modules API #5818

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8347e8b
Modules API: Initial version
luisherranz Dec 22, 2023
27ba624
Move actions to default-filters.php
luisherranz Dec 23, 2023
156eb58
Move module functions to its own file
luisherranz Dec 23, 2023
bbae17c
Use wp_print_inline_script_tag to print import map
luisherranz Dec 23, 2023
76e8726
Divide tests into two files and improve covers
luisherranz Dec 23, 2023
f0fa726
Switch to ReflectionProperty to setStaticPropertyValue
luisherranz Dec 23, 2023
f13a068
Refactor the tests set_up
luisherranz Dec 23, 2023
ef978d8
Test that static dependencies of dynamic dependencies are not preloaded
luisherranz Jan 3, 2024
212cdac
Add since to main class DocBlock
luisherranz Jan 3, 2024
e644da8
Change assertEquals with custom ones
luisherranz Jan 3, 2024
1aa45a6
Avoid static methods and rely on instances
luisherranz Jan 4, 2024
eaaa563
Introduce wrapper functions for printing methods
luisherranz Jan 4, 2024
e30c8e9
Remove space between @since and @var in class properties
luisherranz Jan 4, 2024
a13bc87
Test that version is propagated correctly
luisherranz Jan 4, 2024
67f3900
Cap parameter descriptions to 120 chars
luisherranz Jan 4, 2024
66987f0
Turn $enqueued_before_registered into a map
luisherranz Jan 4, 2024
fda294d
Remove SCRIPT_DEBUG support
luisherranz Jan 4, 2024
c94568d
Rename enqueued to enqueue
luisherranz Jan 8, 2024
2eaf6ea
Add failing test for multiple prints of enqueued modules
luisherranz Jan 8, 2024
4dcfc88
Fix test
luisherranz Jan 8, 2024
a4f9812
Add failing test for multiple prints of preloaded modules
luisherranz Jan 8, 2024
89a82fc
Fix the test
luisherranz Jan 8, 2024
9f08176
Print enqueued and preloaded modules in the head and footer
luisherranz Jan 8, 2024
4b815bc
Move the hooks to the class
luisherranz Jan 9, 2024
bc8c633
Rename `type` key to `import`
luisherranz Jan 9, 2024
b3554d6
Add _doing_it_wrongs
luisherranz Jan 9, 2024
35a9402
Merge remote-tracking branch 'origin/add/modules-api' into add/module…
luisherranz Jan 9, 2024
df73485
Improve @param type of $deps
luisherranz Jan 9, 2024
8fd7501
Indicate how the new print functions work
luisherranz Jan 9, 2024
506784a
Reorder methods
luisherranz Jan 9, 2024
168ae91
Test an empty import map
luisherranz Jan 9, 2024
1df672d
Replace get_version_query_string with get_versioned_src
luisherranz Jan 9, 2024
0cb7f1b
Use `esc_url` instead of `esc_attr` for link's href attribute
luisherranz Jan 9, 2024
834693d
Add suffixes to the ids and an id to the import map
luisherranz Jan 9, 2024
b2ff803
Rename class to WP_Script_Modules
luisherranz Jan 10, 2024
adb5913
Allow wp_enqueue_module to also register modules
luisherranz Jan 10, 2024
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
Refactor the tests set_up
  • Loading branch information
luisherranz committed Dec 23, 2023
commit f13a068c13a694f3fc5fac34c9ec8374200a73a8
39 changes: 14 additions & 25 deletions tests/phpunit/tests/modules/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,13 @@
* @covers WP_Modules::print_module_preloads
*/
class Tests_Modules_Functions extends WP_UnitTestCase {
/**
* Stores a reference to the ReflectionProperty instance of the
* WP_Modules::$registered property.
*
* @var ReflectionProperty
*/
protected $registered;

/**
* Stores the original value of WP_Modules::$registered to restore it later.
*
* @var array
*/
protected $old_registered;

/**
* Stores a reference to the ReflectionProperty instance of the
* WP_Modules::$enqueued_before_registered property.
*
* @var ReflectionProperty
*/
protected $enqueued_before_registered;

/**
* Stores the original value of WP_Modules::$enqueued_before_registered to
* restore it later.
Expand All @@ -43,20 +27,25 @@ class Tests_Modules_Functions extends WP_UnitTestCase {
public function set_up() {
parent::set_up();

$wp_modules = new ReflectionClass( 'WP_Modules' );

$this->old_registered = $wp_modules->getStaticPropertyValue( 'registered' );
$this->old_enqueued_before_registered = $wp_modules->getStaticPropertyValue( 'enqueued_before_registered' );
$registered = new ReflectionProperty( 'WP_Modules', 'registered' );
$registered->setAccessible( true );
$this->old_registered = $registered->getValue();
$registered->setValue( null, array() );

$wp_modules->setStaticPropertyValue( 'registered', array() );
$wp_modules->setStaticPropertyValue( 'enqueued_before_registered', array() );
$enqueued_before_registered = new ReflectionProperty( 'WP_Modules', 'enqueued_before_registered' );
$enqueued_before_registered->setAccessible( true );
$this->old_enqueued_before_registered = $enqueued_before_registered->getValue();
$enqueued_before_registered->setValue( null, array() );
}

public function tear_down() {
$wp_modules = new ReflectionClass( 'WP_Modules' );
$registered = new ReflectionProperty( 'WP_Modules', 'registered' );
$registered->setAccessible( true );
$registered->setValue( null, $this->old_registered );

$wp_modules->setStaticPropertyValue( 'registered', $this->old_registered );
$wp_modules->setStaticPropertyValue( 'enqueued_before_registered', $this->old_enqueued_before_registered );
$enqueued_before_registered = new ReflectionProperty( 'WP_Modules', 'enqueued_before_registered' );
$enqueued_before_registered->setAccessible( true );
$enqueued_before_registered->setValue( null, $this->old_enqueued_before_registered );

parent::tear_down();
}
Expand Down
Loading