- Timestamp:
- 05/07/2026 09:22:08 PM (2 months ago)
- Location:
- branches/7.0
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tests/phpunit/tests/l10n/loadScriptTextdomain.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/7.0
-
branches/7.0/tests/phpunit/tests/l10n/loadScriptTextdomain.php
r61424 r62325 173 173 $this->assertSame( $expected, load_script_textdomain( $handle ) ); 174 174 } 175 176 /** 177 * Tests that an unparseable script source URL short-circuits to 178 * `load_script_translations( false, ... )` instead of falling through 179 * to the relative-path computation. 180 * 181 * @ticket 65015 182 */ 183 public function test_unparseable_src_returns_false(): void { 184 $handle = 'test-unparseable-src'; 185 $src = 'http:///example'; 186 187 $this->assertFalse( wp_parse_url( $src ), 'Test prerequisite failed: the test src should be unparseable.' ); 188 189 wp_enqueue_script( $handle, $src, array(), null ); 190 191 $this->assertFalse( load_script_textdomain( $handle, 'default', DIR_TESTDATA . '/languages' ) ); 192 } 193 194 /** 195 * Tests that an unparseable `content_url()` return value short-circuits 196 * to `load_script_translations( false, ... )` instead of computing 197 * `$relative` from a corrupted parsed-URL array. 198 * 199 * The `MockAction` spy on `pre_load_script_translations` is necessary 200 * here because the function's tail end also calls `load_script_translations( false, ... )`, 201 * so a regression that bypasses the early return would still return false 202 * via the fallback path. Asserting on the recorded `$file` arguments pins 203 * the test to the intended branch. 204 * 205 * @ticket 65015 206 */ 207 public function test_unparseable_content_url_returns_false(): void { 208 $handle = 'test-unparseable-content-url'; 209 $src = '/wp-includes/js/script.js'; 210 211 add_filter( 212 'content_url', 213 static function () { 214 return 'http:///example'; 215 } 216 ); 217 218 $mock = new MockAction(); 219 add_filter( 'pre_load_script_translations', array( $mock, 'filter' ), 10, 4 ); 220 221 wp_enqueue_script( $handle, $src, array(), null ); 222 223 $this->assertFalse( load_script_textdomain( $handle, 'default', DIR_TESTDATA . '/languages' ) ); 224 $this->assertSame( 225 array( 226 DIR_TESTDATA . '/languages/en_US-' . $handle . '.json', 227 false, 228 ), 229 array_column( $mock->get_args(), 1 ), 230 'Expected the unparseable content_url branch to short-circuit before any relative-path lookup.' 231 ); 232 } 233 234 /** 235 * Tests that the `load_script_textdomain_relative_path` filter returning 236 * a non-string, non-false value (e.g., a callback that forgets to return) 237 * short-circuits via the `! is_string( $relative )` guard rather than 238 * falling through to string functions like `str_ends_with()` and `md5()`. 239 * 240 * @ticket 65015 241 */ 242 public function test_non_string_relative_path_filter_returns_false(): void { 243 $handle = 'test-non-string-relative-path'; 244 $src = '/wp-includes/js/script.js'; 245 246 add_filter( 'load_script_textdomain_relative_path', '__return_null' ); 247 248 wp_enqueue_script( $handle, $src, array(), null ); 249 250 $this->assertFalse( load_script_textdomain( $handle, 'default', DIR_TESTDATA . '/languages' ) ); 251 } 252 253 /** 254 * Tests that a script source URL with no path component does not trigger 255 * an undefined index warning when the path is read further down in the 256 * function. The result is reached via the regular fallback path 257 * (no host/path match) rather than an early return. 258 * 259 * @ticket 65015 260 */ 261 public function test_src_without_path_component_does_not_warn(): void { 262 $handle = 'test-src-without-path'; 263 $src = 'https://example.com'; 264 265 $parsed = wp_parse_url( $src ); 266 $this->assertIsArray( $parsed, 'Test prerequisite failed: the test src should parse.' ); 267 $this->assertArrayNotHasKey( 'path', $parsed, 'Test prerequisite failed: the test src should have no path component.' ); 268 269 wp_enqueue_script( $handle, $src, array(), null ); 270 271 $this->assertFalse( load_script_textdomain( $handle, 'default', DIR_TESTDATA . '/languages' ) ); 272 } 175 273 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)