Skip to content

Tests: Add unit tests for the plugin path functions and remove_all_actions() - #15738

Open
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66561-plugin-path-functions-tests
Open

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66561-plugin-path-functions-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for the functions of wp-includes/plugin.php that give the paths of plugins, and for remove_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 returns true for a hook without actions.

Testing

vendor/bin/phpunit --filter 'Tests_Functions_PluginPaths::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Functions_PluginPaths::'
vendor/bin/phpcs tests/phpunit/tests/functions/pluginPaths.php

Mutation check: 14 changes to these functions were each caught by a test, except one that is equivalent on systems that use /: removing wp_normalize_path() from the directory of the file in wp_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.

Trac ticket: https://core.trac.wordpress.org/ticket/66561

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.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@hmbashar
hmbashar marked this pull request as ready for review November 6, 2026 16:09
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props hmbashar, huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests retain Windows compatibility issues: unnormalized registry keys produce incorrect plugin_basename() results, and unlink() fails to remove directory symlinks, leaving them behind.

2 open issues
What changed in this PR

Adds unit tests for plugin path helpers and remove_all_actions() without changing production code.

Changes:

  • Covers plugin directory paths, URLs, and basename normalization.
  • Tests registered symlink paths, path precedence, and realpath registration.
  • Verifies action removal across all priorities, a single priority, and empty hooks.
File Description
tests/​phpunit/​tests/​functions/​pluginPaths.php Adds path-helper and action-removal tests, including symlink fixtures and cleanup.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding tests for plugin path helpers and remove_all_actions(), @hmbashar!

All 97 CI checks pass cleanly across the matrix. Two cross-platform Windows compatibility details to address:

  1. Directory symlink cleanup (line ~54): On Windows, unlink() on a directory symlink can fail. Checking for Windows (DIRECTORY_SEPARATOR === '\\\\') and using rmdir() ensures clean teardown across all platforms.
  2. Path normalization (line ~171): Normalizing backslashes in registered fixture paths with wp_normalize_path() before passing to wp_register_plugin_realpath() prevents absolute path mismatches on Windows.

Great coverage overall!

AI Review: Gemini 3.8 Flash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants