Skip to content

Commit 871d8fb

Browse files
Tests: Add 'false' version cases to duplicate query var data providers.
Updates regression tests to include coverage for 'false' version strings, which trigger the default WordPress version. Also refines parameter type hints to accurately reflect allowed 'string|bool|null' values. Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent d8a07c1 commit 871d8fb

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

tests/phpunit/tests/dependencies/scripts.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,12 +4199,12 @@ public function test_varying_versions_added_to_handle_args_registered_then_enque
41994199
*
42004200
* @dataProvider data_duplicate_query_vars_and_fragments_preserved_in_scripts
42014201
*
4202-
* @param string $src The script's source URL.
4203-
* @param string|null $ver The script's version.
4204-
* @param string $expected_url The expected URL.
4205-
* @param string $handle Optional. The script's registered handle. Default 'test-script'.
4202+
* @param string $src The script's source URL.
4203+
* @param string|bool|null $ver The script's version.
4204+
* @param string $expected_url The expected URL.
4205+
* @param string $handle Optional. The script's registered handle. Default 'test-script'.
42064206
*/
4207-
public function test_duplicate_query_vars_and_fragments_preserved_in_scripts( string $src, ?string $ver, string $expected_url, string $handle = 'test-script' ): void {
4207+
public function test_duplicate_query_vars_and_fragments_preserved_in_scripts( string $src, $ver, string $expected_url, string $handle = 'test-script' ): void {
42084208
wp_enqueue_script( $handle, $src, array(), $ver );
42094209
$output = get_echo( 'wp_print_scripts' );
42104210
$processor = new WP_HTML_Tag_Processor( $output );
@@ -4216,32 +4216,39 @@ public function test_duplicate_query_vars_and_fragments_preserved_in_scripts( st
42164216
/**
42174217
* Data provider for test_duplicate_query_vars_and_fragments_preserved_in_scripts.
42184218
*
4219-
* @return array<string, array{src: string, ver: string|null, expected_url: string, handle?: string}> Data provider.
4219+
* @return array<string, array{src: string, ver: string|bool|null, expected_url: string, handle?: string}> Data provider.
42204220
*/
42214221
public function data_duplicate_query_vars_and_fragments_preserved_in_scripts(): array {
4222+
$ver = get_bloginfo( 'version' );
4223+
42224224
return array(
4223-
'duplicate query vars' => array(
4225+
'duplicate query vars' => array(
42244226
'src' => 'https://example.com/script.js?arg=1&arg=2',
42254227
'ver' => '1.0',
42264228
'expected_url' => 'https://example.com/script.js?arg=1&arg=2&ver=1.0',
42274229
),
4228-
'duplicate query vars, null version' => array(
4230+
'duplicate query vars, null version' => array(
42294231
'src' => 'https://example.com/script.js?arg=1&arg=2',
42304232
'ver' => null,
42314233
'expected_url' => 'https://example.com/script.js?arg=1&arg=2',
42324234
),
4233-
'duplicate query vars in handle' => array(
4235+
'duplicate query vars, false version' => array(
4236+
'src' => 'https://example.com/script.js?arg=1&arg=2',
4237+
'ver' => false,
4238+
'expected_url' => "https://example.com/script.js?arg=1&arg=2&ver=$ver",
4239+
),
4240+
'duplicate query vars in handle' => array(
42344241
'src' => 'https://example.com/test-script.js',
42354242
'ver' => '1.0',
42364243
'expected_url' => 'https://example.com/test-script.js?ver=1.0&a=1&a=2',
42374244
'handle' => 'test-script?a=1&a=2',
42384245
),
4239-
'duplicate query vars and fragments' => array(
4246+
'duplicate query vars and fragments' => array(
42404247
'src' => 'https://example.com/script.js?arg=1&arg=2#anchor',
42414248
'ver' => '1.0',
42424249
'expected_url' => 'https://example.com/script.js?arg=1&arg=2&ver=1.0#anchor',
42434250
),
4244-
'zero query var in handle' => array(
4251+
'zero query var in handle' => array(
42454252
'src' => 'https://example.com/test-script.js',
42464253
'ver' => '1.0',
42474254
'expected_url' => 'https://example.com/test-script.js?ver=1.0&0',

tests/phpunit/tests/dependencies/styles.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -968,12 +968,12 @@ public function test_varying_versions_added_to_handle_args_registered_then_enque
968968
*
969969
* @dataProvider data_duplicate_query_vars_and_fragments_preserved_in_styles
970970
*
971-
* @param string $src The stylesheet's source URL.
972-
* @param string|null $ver The style's version.
973-
* @param string $expected_url The expected URL.
974-
* @param string $handle Optional. The style's registered handle. Default 'test-style'.
971+
* @param string $src The stylesheet's source URL.
972+
* @param string|bool|null $ver The style's version.
973+
* @param string $expected_url The expected URL.
974+
* @param string $handle Optional. The style's registered handle. Default 'test-style'.
975975
*/
976-
public function test_duplicate_query_vars_and_fragments_preserved_in_styles( string $src, ?string $ver, string $expected_url, string $handle = 'test-style' ): void {
976+
public function test_duplicate_query_vars_and_fragments_preserved_in_styles( string $src, $ver, string $expected_url, string $handle = 'test-style' ): void {
977977
wp_enqueue_style( $handle, $src, array(), $ver );
978978
$output = get_echo( 'wp_print_styles' );
979979
$processor = new WP_HTML_Tag_Processor( $output );
@@ -985,32 +985,39 @@ public function test_duplicate_query_vars_and_fragments_preserved_in_styles( str
985985
/**
986986
* Data provider for test_duplicate_query_vars_and_fragments_preserved_in_styles.
987987
*
988-
* @return array<string, array{src: string, ver: string|null, expected_url: string, handle?: string}> Data provider.
988+
* @return array<string, array{src: string, ver: string|bool|null, expected_url: string, handle?: string}> Data provider.
989989
*/
990990
public function data_duplicate_query_vars_and_fragments_preserved_in_styles(): array {
991+
$ver = get_bloginfo( 'version' );
992+
991993
return array(
992-
'duplicate query vars' => array(
994+
'duplicate query vars' => array(
993995
'src' => 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap',
994996
'ver' => '1.0',
995997
'expected_url' => 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap&ver=1.0',
996998
),
997-
'duplicate query vars, null version' => array(
999+
'duplicate query vars, null version' => array(
9981000
'src' => 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap',
9991001
'ver' => null,
10001002
'expected_url' => 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap',
10011003
),
1002-
'duplicate query vars in handle' => array(
1004+
'duplicate query vars, false version' => array(
1005+
'src' => 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap',
1006+
'ver' => false,
1007+
'expected_url' => "https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap&ver=$ver",
1008+
),
1009+
'duplicate query vars in handle' => array(
10031010
'src' => 'https://example.com/test-style.css',
10041011
'ver' => '1.0',
10051012
'expected_url' => 'https://example.com/test-style.css?ver=1.0&a=1&a=2',
10061013
'handle' => 'test-style?a=1&a=2',
10071014
),
1008-
'duplicate query vars and fragments' => array(
1015+
'duplicate query vars and fragments' => array(
10091016
'src' => 'https://example.com/style.css?arg=1&arg=2#anchor',
10101017
'ver' => '1.0',
10111018
'expected_url' => 'https://example.com/style.css?arg=1&arg=2&ver=1.0#anchor',
10121019
),
1013-
'zero query var in handle' => array(
1020+
'zero query var in handle' => array(
10141021
'src' => 'https://example.com/test-style.css',
10151022
'ver' => '1.0',
10161023
'expected_url' => 'https://example.com/test-style.css?ver=1.0&0',

0 commit comments

Comments
 (0)