Make WordPress Core

Opened 6 days ago

Last modified 6 days ago

#66552 new enhancement

Tests: Add unit test coverage for WP_Plugins_List_Table

Reported by: huzaifaalmesbah Owned by:
Priority: normal Milestone: Awaiting Review
Component: Plugins Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

src/wp-admin/includes/class-wp-plugins-list-table.php contains 822 lines across 22 methods responsible for managing and displaying installed plugins in the WordPress admin (wp-admin/plugins.php).

According to local PHPUnit code coverage analysis, WP_Plugins_List_Table currently has 0.00% unit test coverage (0/22 methods and 0/822 lines covered). There are no dedicated test cases exercising its configuration, capability checks, search callbacks, or row display logic.

Proposed Changes

Add a dedicated PHPUnit test suite for WP_Plugins_List_Table in tests/phpunit/tests/admin/wpPluginsListTable.php to cover:

  1. Table initialization and configuration:
    • ajax_user_can(): verify capability checks for activate_plugins.
    • get_table_classes(): assert the expected table class names (plugins, wp-list-table, widefat).
    • get_columns() and get_sortable_columns(): assert default columns and sortable definitions.
    • get_primary_column_name(): verify primary column designation (name).
  1. Search and filtering:
    • _search_callback(): assert filtering against plugin name, description, author, and tags.
  1. Bulk actions and tablenav:
    • bulk_actions(): verify bulk action options for single-site and multisite contexts.
    • extra_tablenav() and current_action(): verify action resolution and markup output.
  1. Row rendering:
    • single_row() and display_rows(): assert output formatting for active, inactive, and auto-update-enabled plugins.

Change History (1)

This ticket was mentioned in ​PR #15715 on ​WordPress/wordpress-develop by ​@hmbashar.


6 days ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

Summary

Adds tests for the parts of WP_Plugins_List_Table that the existing tests do not cover, in tests/phpunit/tests/admin/wpPluginsListTable.php. The class already has tests for the bulk actions, the action links, the dependency rows, the search box and prepare_items() in other files, so these tests add the methods listed in the ticket that were still missing.

  • __construct(): the search term is added to the request URI.
  • ajax_user_can(), get_table_classes(), get_primary_column_name().
  • get_columns(): the default columns and the automatic updates column.
  • _search_callback(): the name, description (without markup), author, URL-encoded terms, values that are not strings.
  • get_views(): the label of other statuses, the plugins_list_status_text filter, escaping, and statuses without plugins.
  • bulk_actions(), extra_tablenav() (the Clear List button and the Must-Use and Drop-ins notes) and current_action().
  • display_rows(), including Must-Use plugins and drop-ins on a site of a network.
  • single_row(): the setting for automatic updates, the plugin_auto_update_setting_html filter, custom columns, drop-in rows and the message for a plugin that is not compatible.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_wpPluginsListTable'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_wpPluginsListTable'
vendor/bin/phpcs tests/phpunit/tests/admin/wpPluginsListTable.php

Mutation check: 38 changes to class-wp-plugins-list-table.php (the capability, the search, the views, the table navigation, the drop-in rows, the automatic updates setting and the compatibility message) were each caught by a test. The two that depend on multisite are caught by the multisite run.

Notes: the compatibility message for a user who can update WordPress but not PHP (and the reverse) is tested with a map_meta_cap filter, because update_php maps to update_core.

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.

Note: See TracTickets for help on using tickets.