From c60501b963335440b010f54c6ac4894b475e1b20 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 5 May 2026 17:45:40 -0400 Subject: [PATCH 1/2] Add unit tests for wp_make_theme_file_tree() in wp-admin/includes/misc.php --- .../includes/misc/wpMakeThemeFileTree.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php diff --git a/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php b/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php new file mode 100644 index 0000000000000..5579a959330ce --- /dev/null +++ b/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php @@ -0,0 +1,98 @@ +assertSame( $expected, wp_make_theme_file_tree( $allowed_files ) ); + } + + /** + * Data provider for test_wp_make_theme_file_tree. + * + * @return array, + * expected: array, + * }> + */ + public function data_wp_make_theme_file_tree(): array { + return array( + 'empty_list' => array( + 'allowed_files' => array(), + 'expected' => array(), + ), + 'flat_list' => array( + 'allowed_files' => array( + 'style.css' => '/path/to/theme/style.css', + 'index.php' => '/path/to/theme/index.php', + ), + 'expected' => array( + 'style.css' => 'style.css', + 'index.php' => 'index.php', + ), + ), + 'nested_list' => array( + 'allowed_files' => array( + 'style.css' => '/path/to/theme/style.css', + 'inc/header.php' => '/path/to/theme/inc/header.php', + 'inc/footer.php' => '/path/to/theme/inc/footer.php', + 'templates/a.php' => '/path/to/theme/templates/a.php', + ), + 'expected' => array( + 'style.css' => 'style.css', + 'inc' => array( + 'header.php' => 'inc/header.php', + 'footer.php' => 'inc/footer.php', + ), + 'templates' => array( + 'a.php' => 'templates/a.php', + ), + ), + ), + 'deeply_nested_list' => array( + 'allowed_files' => array( + 'a/b/c/d.php' => '/path/to/theme/a/b/c/d.php', + ), + 'expected' => array( + 'a' => array( + 'b' => array( + 'c' => array( + 'd.php' => 'a/b/c/d.php', + ), + ), + ), + ), + ), + 'mixed_nesting' => array( + 'allowed_files' => array( + 'index.php' => '/path/to/theme/index.php', + 'inc/header.php' => '/path/to/theme/inc/header.php', + 'inc/utils/a.php' => '/path/to/theme/inc/utils/a.php', + ), + 'expected' => array( + 'index.php' => 'index.php', + 'inc' => array( + 'header.php' => 'inc/header.php', + 'utils' => array( + 'a.php' => 'inc/utils/a.php', + ), + ), + ), + ), + ); + } +} From cb5227d7b455b8338d54a3a567644d754c840845 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 5 May 2026 18:06:55 -0400 Subject: [PATCH 2/2] Fix array key formatting in wpMakeThemeFileTree test --- .../tests/admin/includes/misc/wpMakeThemeFileTree.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php b/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php index 5579a959330ce..a5f428f2f78a9 100644 --- a/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php +++ b/tests/phpunit/tests/admin/includes/misc/wpMakeThemeFileTree.php @@ -31,11 +31,11 @@ public function test_wp_make_theme_file_tree( $allowed_files, $expected ) { */ public function data_wp_make_theme_file_tree(): array { return array( - 'empty_list' => array( + 'empty_list' => array( 'allowed_files' => array(), 'expected' => array(), ), - 'flat_list' => array( + 'flat_list' => array( 'allowed_files' => array( 'style.css' => '/path/to/theme/style.css', 'index.php' => '/path/to/theme/index.php', @@ -45,7 +45,7 @@ public function data_wp_make_theme_file_tree(): array { 'index.php' => 'index.php', ), ), - 'nested_list' => array( + 'nested_list' => array( 'allowed_files' => array( 'style.css' => '/path/to/theme/style.css', 'inc/header.php' => '/path/to/theme/inc/header.php', @@ -63,7 +63,7 @@ public function data_wp_make_theme_file_tree(): array { ), ), ), - 'deeply_nested_list' => array( + 'deeply_nested_list' => array( 'allowed_files' => array( 'a/b/c/d.php' => '/path/to/theme/a/b/c/d.php', ), @@ -77,7 +77,7 @@ public function data_wp_make_theme_file_tree(): array { ), ), ), - 'mixed_nesting' => array( + 'mixed_nesting' => array( 'allowed_files' => array( 'index.php' => '/path/to/theme/index.php', 'inc/header.php' => '/path/to/theme/inc/header.php',