From 0d3319ebc730ccd7573212ca44f3353ea1651e41 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 5 May 2026 18:08:27 -0400 Subject: [PATCH] Add unit tests for wp_make_plugin_file_tree() in wp-admin/includes/misc.php --- .../includes/misc/wpMakePluginFileTree.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/phpunit/tests/admin/includes/misc/wpMakePluginFileTree.php diff --git a/tests/phpunit/tests/admin/includes/misc/wpMakePluginFileTree.php b/tests/phpunit/tests/admin/includes/misc/wpMakePluginFileTree.php new file mode 100644 index 0000000000000..7489ce44a498e --- /dev/null +++ b/tests/phpunit/tests/admin/includes/misc/wpMakePluginFileTree.php @@ -0,0 +1,89 @@ +assertSame( $expected, wp_make_plugin_file_tree( $plugin_editable_files ) ); + } + + /** + * Data provider for test_wp_make_plugin_file_tree. + * + * @return array, + * expected: array, + * }> + */ + public function data_wp_make_plugin_file_tree(): array { + return array( + 'empty_list' => array( + 'plugin_editable_files' => array(), + 'expected' => array(), + ), + 'flat_list' => array( + 'plugin_editable_files' => array( + 'plugin/plugin.php', + 'plugin/readme.txt', + ), + 'expected' => array( + 'plugin.php' => 'plugin/plugin.php', + 'readme.txt' => 'plugin/readme.txt', + ), + ), + 'nested_list' => array( + 'plugin_editable_files' => array( + 'plugin/plugin.php', + 'plugin/includes/class-plugin.php', + 'plugin/includes/functions.php', + ), + 'expected' => array( + 'plugin.php' => 'plugin/plugin.php', + 'includes' => array( + 'class-plugin.php' => 'plugin/includes/class-plugin.php', + 'functions.php' => 'plugin/includes/functions.php', + ), + ), + ), + 'deeply_nested_list' => array( + 'plugin_editable_files' => array( + 'plugin/plugin.php', + 'plugin/src/components/button/index.js', + ), + 'expected' => array( + 'plugin.php' => 'plugin/plugin.php', + 'src' => array( + 'components' => array( + 'button' => array( + 'index.js' => 'plugin/src/components/button/index.js', + ), + ), + ), + ), + ), + 'multiple_base_names' => array( + 'plugin_editable_files' => array( + 'plugin-a/plugin.php', + 'plugin-b/plugin.php', + ), + 'expected' => array( + 'plugin.php' => 'plugin-b/plugin.php', // Note: wp_make_plugin_file_tree replaces the file name if multiple base paths exist but result in same relative path. + ), + ), + ); + } +}