Changeset 61857 for trunk/tests/phpunit/tests/functions.php
- Timestamp:
- 03/06/2026 08:04:31 PM (3 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r61328 r61857 223 223 array( 'http://example.com//path.ext', 'http://example.com/path.ext' ), 224 224 array( 'file://c:\\www\\path\\', 'file://C:/www/path/' ), 225 ); 225 226 // Edge cases. 227 array( '', '' ), // Empty string should return empty string. 228 array( 123, '123' ), // Integer should be cast to string. 229 ); 230 } 231 232 /** 233 * Tests that wp_normalize_path() works with objects that have __toString(). 234 * 235 * This is important because the function uses a static cache, and the input 236 * must be cast to string before being used as an array key. 237 * 238 * @ticket 64538 239 */ 240 public function test_wp_normalize_path_with_stringable_object() { 241 $file_info = new SplFileInfo( '/var/www/html\\test' ); 242 243 $this->assertSame( '/var/www/html/test', wp_normalize_path( $file_info ) ); 244 } 245 246 /** 247 * Tests that wp_normalize_path() returns consistent results on repeated calls. 248 * 249 * The function uses a static cache, so this verifies cache behavior. 250 * 251 * @ticket 64538 252 */ 253 public function test_wp_normalize_path_returns_consistent_results() { 254 $path = 'C:\\www\\path\\'; 255 256 $first_call = wp_normalize_path( $path ); 257 $second_call = wp_normalize_path( $path ); 258 $third_call = wp_normalize_path( $path ); 259 260 $this->assertSame( $first_call, $second_call, 'Second call should return same result as first.' ); 261 $this->assertSame( $second_call, $third_call, 'Third call should return same result as second.' ); 262 $this->assertSame( 'C:/www/path/', $first_call, 'Normalized path should match expected value.' ); 263 } 264 265 /** 266 * Tests that wp_normalize_path() static cache stores results. 267 * 268 * @ticket 64538 269 */ 270 public function test_wp_normalize_path_static_cache() { 271 $path = '/var/www/cache-test\\subdir\\'; 272 $expected = '/var/www/cache-test/subdir/'; 273 274 $result = wp_normalize_path( $path ); 275 $this->assertSame( $expected, $result ); 276 277 $reflection = new ReflectionFunction( 'wp_normalize_path' ); 278 $static_vars = $reflection->getStaticVariables(); 279 280 $this->assertArrayHasKey( 'cache', $static_vars, 'Static cache array should exist.' ); 281 $this->assertArrayHasKey( $path, $static_vars['cache'], 'Cache should contain the normalized path.' ); 282 $this->assertSame( $expected, $static_vars['cache'][ $path ], 'Cached value should match the expected normalized path.' ); 226 283 } 227 284
Note: See TracChangeset
for help on using the changeset viewer.