Skip to content

Tests: Add unit tests for get_plugin_data(), get_plugins() and get_plugin_files() - #15719

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66556-plugin-data-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66556-plugin-data-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for get_plugin_data(), get_plugins() and get_plugin_files(). get_plugin_data_markup_translate and get_plugin_files() (a single file and a folder) already have tests, so these tests cover the rest.

getPluginData.php

  • All the headers are read: name, URI, version, description, author, author URI, text domain, domain path, Network, Requires at least, Requires PHP, Update URI and Requires Plugins.
  • The headers that are missing are empty, and the plugin folder is the text domain when there is none (but not for a file in the plugins directory).
  • The Network header is read as a boolean, and the deprecated Site Wide Only header is read and reported, unless Network is set.
  • Without markup and translation the data is not changed, with markup the title and author are linked, and markup works without translation.

getPlugins.php

  • A plugin file in the plugins directory, a plugin in a folder and several plugin files in a folder are found.
  • Files in folders that are too deep, without a header, that are not PHP files, and hidden files and folders are ignored.
  • The data is returned without markup, sorted by name, and for one folder when a folder is passed (nothing for a folder that does not exist).
  • The result is cached by folder, and read again after wp_clean_plugins_cache().
  • get_plugin_files() lists the files of the plugin folder, leaves out CVS, node_modules, vendor and bower_components, uses the plugin_files_exclusions filter, and lists a plugin file in the plugins directory alone.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_Includes_Plugin_(GetPluginData|GetPlugins)::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_Includes_Plugin_(GetPluginData|GetPlugins)::'
vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin/getPluginData.php tests/phpunit/tests/admin/includes/plugin/getPlugins.php

Mutation check: 25 changes to the three functions (the headers, the deprecated header, the text domain, the markup branch, the file and folder checks, the sorting, the cache and the exclusions) were each caught by a test.

The tests write plugins into the plugins directory with a random name, and remove them (hidden files and folders included) after each test.

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

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.

@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 test fixtures cannot detect regressions in name-based sorting or hidden-directory exclusion because name and filename ordering coincide, and the hidden plugin sits beyond the scanning depth.

2 open issues
What changed in this PR

Adds PHPUnit coverage for WordPress plugin metadata, discovery, and file listing without changing production code.

Changes:

  • Tests plugin headers, text-domain defaults, deprecated headers, and markup behavior.
  • Tests plugin discovery, sorting, folder-specific results, and caching.
  • Tests plugin file listings and exclusions, with temporary fixtures and cleanup.
File Description
tests/​phpunit/​tests/​admin/​includes/​plugin/​getPlugins.php Adds discovery, caching, sorting, and file-listing tests.
tests/​phpunit/​tests/​admin/​includes/​plugin/​getPluginData.php Adds metadata, header fallback, and markup tests.

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 coverage for plugin discovery and header parsing, @hmbashar!

All CI checks pass cleanly. Two edge-case improvements to make the tests even more resilient:

  1. Name sorting test fixture (line ~171): In the sort test, the directory/file names and the plugin header names currently follow the same alphabetical order (a-plugin -> "A Plugin", b-plugin -> "B Plugin"). If name-sorting regressed to sorting by path/key, the test would still pass. Inverting the names (e.g. z-plugin named "Alpha Plugin") would ensure true name-based sorting is verified.
  2. Hidden directory exclusion (line ~114): Placing the hidden directory directly in WP_PLUGIN_DIR rather than two levels down ensures it tests the hidden-directory filter rather than being excluded by get_plugins()' 1-level depth limit.

Solid work overall!

AI Review: Gemini 3.8 Flash

… by a name that differs from the file.

See #66556.
@hmbashar hmbashar closed this Nov 12, 2026
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