Skip to content

Tests: Add unit test coverage for _get_plugin_data_markup_translate() - #14522

Open
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugin-data-markup-translate
Open

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugin-data-markup-translate

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds tests for _get_plugin_data_markup_translate(), which translates, sanitizes and marks up the plugin header data shown on the Plugins screen. The only existing coverage is test_get_plugin_data(), which checks the markup of Hello Dolly; the translation path, the sanitization of untrusted header values and the empty-field cases had no tests.

The tests call the function directly with header data, record translate() calls through the gettext filter, and replace the text domain registry with a mock to check where the text domain is loaded from. They cover:

  • wp_kses() on the name (no links), author, description and version, and esc_url() on both URIs, using markup, disallowed tags, attributes and entity characters;
  • Title and AuthorName holding the sanitized values without markup;
  • the linked title and author, the texturized description and the "By %s." credit with markup;
  • no link or credit when the plugin URI, name, author URI or author is empty, including an author of '0';
  • translation of the non-empty fields with the plugin's text domain, and no translation when it is disabled;
  • Hello Dolly falling back to the default text domain (also inside a plugin directory), and other plugins without a text domain not being translated;
  • the text domain being loaded from the plugin directory or its Domain Path, and not again when it is already loaded.

Removing or changing each branch of the function makes at least one test fail.

This is a test-only change; no production code is modified.

Testing Instructions

  1. Run the tests on single site:
    npm run test:php -- --filter Tests_Admin_Includes_Plugin_GetPluginDataMarkupTranslate
  2. Run them on multisite:
    npm run test:php -- --filter Tests_Admin_Includes_Plugin_GetPluginDataMarkupTranslate -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter Tests_Admin_Includes_Plugin_GetPluginDataMarkupTranslate --order-by=random
  4. Run the plugins group:
    npm run test:php -- --group plugins
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin/getPluginDataMarkupTranslate.php

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review October 20, 2026 05:35
@github-actions

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props huzaifaalmesbah.

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

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.

2 participants