Skip to content

Tests: Add unit tests for the data and the sections of install_plugin_information() - #15748

Open
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66566-install-plugin-information-sections-tests
Open

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66566-install-plugin-information-sections-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Part 1 of the tests for install_plugin_information() (ticket #66566): the data and the sections. The function outputs the screen with the details of a plugin and ends the request, so the tests stop it with an action of the footer before that. The sidebar with the details of the plugin and the notices and the button in the footer are in other pull requests.

  • Nothing is output without a plugin in the request, and the screen dies with the error of the API. The API is asked for the unslashed plugin.
  • The title of the screen and the name of the plugin are output.
  • The markup that is not allowed is removed from the sections and from the fields of the plugin (version, author).
  • The banner: low and high, only one of them, empty banners, and no banners.
  • A tab is linked for each section with its title (the known titles and a title made from the name), the tab of the reviews only with ratings, and the tabs link with the tab and the section.
  • The section that is shown: the requested one, the description by default, and the first one when the section is empty, is not there or the plugin has no description. The others are hidden, and one tab is the current one.
  • The links of the sections are made absolute for the plugin page and open in a new tab.

Testing

vendor/bin/phpunit --filter 'Admin_Includes_Plugin_Install_InstallPluginInformationSections_Test::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Admin_Includes_Plugin_Install_InstallPluginInformationSections_Test::'
vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin-install/InstallPluginInformationSections_Test.php

Mutation check: 20 changes to this part of the function (the request, the sanitizing, the section that is shown, the banner, the tabs, the titles and the links) were each caught by a test. Removing empty( $section ) is equivalent, because an empty section is not a key of the sections either.

The screen sends headers, which PHP refuses because the tests have output already, so the tests ignore that warning only. Other errors are still reported.

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

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 17:57
@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 error-handler wrapper uses E_WARNING instead of E_ALL, bypassing PHPUnit’s handler for other error levels and allowing unexpected errors during render() to go undetected by the tests.

1 open issue
What changed in this PR

Adds the first set of unit tests for install_plugin_information() under ticket #66566, covering plugin data and sections without changing production code.

Changes:

  • Adds fixtures and a rendering helper that stops execution before the screen ends the request.
  • Tests request handling, API errors, titles, markup sanitization, and banners.
  • Covers section tabs, review-tab visibility, section selection, and link rewriting.
File Description
tests/​phpunit/​tests/​admin/​includes/​plugin-install/​InstallPluginInformationSections_Test.php Adds unit tests for plugin information data and section rendering.

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 working on this, @hmbashar! Splitting the install_plugin_information() coverage into focused parts is a great approach, and intercepting the screen via an admin footer exception handles output buffering cleanly.

All 97 CI checks are passing.

One observation on the custom error handler in render() (around line 159):
Currently, set_error_handler() is registered with E_WARNING. Because of that mask, other PHP diagnostic levels (like notices or deprecations) bypass this wrapper and go straight to PHP's default handler rather than PHPUnit's $previous_handler. Changing E_WARNING to E_ALL will ensure any unexpected notices or deprecations during render are properly caught and forwarded to the test runner.

Great work on this suite!

AI Review: Gemini 3.8 Flash

@hmbashar

hmbashar commented Nov 6, 2026

Copy link
Copy Markdown
Author

Thanks for the review, @huzaifaalmesbah. Changed the error handler mask from E_WARNING to E_ALL in 8d45b9d.

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