Opened 13 hours ago
Last modified 13 hours ago
#66561 new enhancement
Tests: Add unit tests for plugin_dir_path(), plugin_dir_url(), plugin_basename(), wp_register_plugin_realpath() and remove_all_actions()
| Reported by: | hmbashar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Plugins | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
plugin_dir_path(), plugin_dir_url(), wp_register_plugin_realpath() and remove_all_actions() in wp-includes/plugin.php have no unit tests, and plugin_basename() is only used by other tests.
This ticket adds tests for the trailing slash of the directory and the URL of a plugin file, the path relative to the plugins and Must-Use plugins directories (with backslashes, extra slashes and paths outside of them), the real path of a plugin that is a symbolic link and how plugin_basename() uses it, and removing all the actions of a hook, or of a priority.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Summary
Adds tests for the functions of
wp-includes/plugin.phpthat give the paths of plugins, and forremove_all_actions(). None of them had a test of its own.plugin_dir_path()returns the directory of a file with a trailing slash.plugin_dir_url()returns the URL of the directory of a plugin file (and of a Must-Use plugin file) with a trailing slash.plugin_basename()returns the path relative to the plugins directory, or the Must-Use plugins directory, for a plugin in a folder, a single file, a file in a subfolder, a path with backslashes or extra slashes, a relative path and a path outside of them. It uses the registered path of a plugin that is a symbolic link, and the most specific registered path first.wp_register_plugin_realpath()registers nothing for a file in the plugins or Must-Use plugins directory, or for a plugin that is not a link, and registers the real path of a plugin that is a symbolic link (the test is skipped when links cannot be created).remove_all_actions()removes the actions of all the priorities or of one priority, and returnstruefor a hook without actions.Testing
Mutation check: 14 changes to these functions were each caught by a test, except one that is equivalent on systems that use
/: removingwp_normalize_path()from the directory of the file inwp_register_plugin_realpath().The test with a symbolic link creates a folder in the temporary directory and a link in the plugins directory, and removes both after the test.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.