Changeset 57215
- Timestamp:
- 12/20/2023 08:00:04 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r57118 r57215 225 225 */ 226 226 function _get_block_templates_paths( $base_directory ) { 227 static $template_path_list = array(); 228 if ( isset( $template_path_list[ $base_directory ] ) ) { 229 return $template_path_list[ $base_directory ]; 230 } 227 231 $path_list = array(); 228 if ( file_exists( $base_directory ) ){232 try { 229 233 $nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) ); 230 234 $nested_html_files = new RegexIterator( $nested_files, '/^.+\.html$/i', RecursiveRegexIterator::GET_MATCH ); … … 232 236 $path_list[] = $path; 233 237 } 234 } 238 } catch ( Exception $e ) { 239 // Do nothing. 240 } 241 $template_path_list[ $base_directory ] = $path_list; 235 242 return $path_list; 236 243 } -
trunk/tests/phpunit/tests/block-template.php
r57019 r57215 389 389 390 390 /** 391 * Tests `_get_block_templates_paths()` for an invalid directory. 392 * 393 * @ticket 58196 394 * 395 * @covers ::_get_block_templates_paths 396 */ 397 public function test_get_block_templates_paths_dir_exists() { 398 $theme_dir = get_template_directory(); 399 // Templates in the current theme. 400 $templates = array( 401 'parts/small-header.html', 402 'templates/custom-single-post-template.html', 403 'templates/index.html', 404 'templates/page-home.html', 405 'templates/page.html', 406 'templates/single.html', 407 ); 408 409 $expected_template_paths = array_map( 410 static function ( $template ) use ( $theme_dir ) { 411 return $theme_dir . '/' . $template; 412 }, 413 $templates 414 ); 415 416 $template_paths = _get_block_templates_paths( $theme_dir ); 417 $this->assertSameSets( $expected_template_paths, $template_paths ); 418 } 419 420 /** 421 * Test _get_block_templates_paths() for a invalid dir. 422 * 423 * @ticket 58196 424 * 425 * @covers ::_get_block_templates_paths 426 */ 427 public function test_get_block_templates_paths_dir_doesnt_exists() { 428 // Should return empty array for invalid path. 429 $template_paths = _get_block_templates_paths( '/tmp/random-invalid-theme-path' ); 430 $this->assertSame( array(), $template_paths ); 431 } 432 433 /** 391 434 * Registers a test block to log `in_the_loop()` results. 392 435 *
Note: See TracChangeset
for help on using the changeset viewer.