Skip to content

Commit 883bb4f

Browse files
committed
WP/EnqueuedResourceParameters: add tests for namespaced names
I'm adding two different tests for fully qualified global function calls to cover all the global functions that are referenced directly in the `EnqueuedResourceParametersSniff::process_parameters` method.
1 parent 84e1d99 commit 883bb4f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.1.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,12 @@ wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array
108108
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), \Null, true ); // Error - 0, false or NULL are not allowed.
109109
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), \true, true ); // Ok.
110110
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), \get_version(), true ); // OK.
111+
112+
/*
113+
* Safeguard correct handling of all types of namespaced function calls.
114+
*/
115+
\wp_enqueue_script( 'script-name', 'https://example.com/someScript.js', false, '1.1.0' ); // Error - missing $in_footer.
116+
\wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), '1.1.0' ); // Error - missing $in_footer.
117+
MyNamespace\wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), '1.1.0' ); // Ok.
118+
\MyNamespace\wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), '1.1.0' ); // Ok.
119+
namespace\wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), '1.1.0' ); // The sniff should start flagging this once it can resolve relative namespaces.

WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public function getWarningList( $testFile = '' ) {
8282
100 => 1,
8383
107 => 1,
8484
108 => 1,
85+
115 => 1,
86+
116 => 1,
8587
);
8688

8789
default:

0 commit comments

Comments
 (0)