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..a5f428f2f78a9 --- /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', + ), + ), + ), + ), + ); + } +}