Skip to content

Tests: Add unit test coverage for Connector Approval Admin_Page and Admin_Notice - #1134

Open
noruzzamans wants to merge 2 commits into
WordPress:developfrom
noruzzamans:test/connector-approval-admin-page-and-notice
Open

noruzzamans wants to merge 2 commits into
WordPress:developfrom
noruzzamans:test/connector-approval-admin-page-and-notice

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What?

Adds dedicated unit and integration test coverage for WordPress\AI\Experiments\Connector_Approval\Admin_Page (tests/Integration/Includes/Experiments/Connector_Approval/Admin_PageTest.php) and extends test coverage for WordPress\AI\Connector_Approval\Admin_Notice (tests/Integration/Includes/Connector_Approval/Admin_NoticeTest.php).

Why?

While the Connector Approval subsystem includes unit tests for Approvals_Store, Caller_Identifier, Connector_Key_Index, Http_Guard, REST_Controller, and Connector_Approval, the administrative page controller WordPress\AI\Experiments\Connector_Approval\Admin_Page (includes/Experiments/Connector_Approval/Admin_Page.php) lacked a dedicated test suite (0% direct test coverage). Additionally, Admin_NoticeTest only covered screen-level CSS class checks while leaving hook registration, capability guards, empty queue handling, singular/plural message formatting, and dismissal signature persistence/invalidation untested.

How?

  1. Added tests/Integration/Includes/Experiments/Connector_Approval/Admin_PageTest.php covering WordPress\AI\Experiments\Connector_Approval\Admin_Page:

    • test_url_returns_expected_admin_url: Verifies Admin_Page::url() returns the expected tools.php?page=ai-connector-approval admin URL.
    • test_register_adds_admin_hooks: Verifies register() attaches add_submenu to admin_menu and enqueue_assets to admin_enqueue_scripts.
    • test_add_submenu_registers_tools_submenu_for_administrator: Verifies add_submenu() registers the ai-connector-approval submenu under tools.php with manage_options capability.
    • test_enqueue_assets_bails_on_non_matching_hook_suffix: Verifies enqueue_assets() returns early without enqueuing assets on unrelated admin screens.
    • test_enqueue_assets_enqueues_script_style_and_localizes_data_on_matching_hook: Verifies enqueue_assets() enqueues the ai_connector_approval script and style and localizes aiConnectorApproval with the REST endpoint URL and nonce on tools_page_ai-connector-approval.
    • test_render_requires_manage_options_capability: Verifies render() terminates via wp_die() when the current user lacks manage_options.
    • test_render_outputs_page_container_for_administrator: Verifies render() outputs the heading and #ai-connector-approval-root mount container for administrators.
  2. Extended tests/Integration/Includes/Connector_Approval/Admin_NoticeTest.php covering WordPress\AI\Connector_Approval\Admin_Notice:

    • test_register_adds_admin_hooks: Verifies register() hooks maybe_handle_dismiss on admin_init and render on admin_notices.
    • test_render_skips_users_without_manage_options: Verifies render() outputs nothing for users without manage_options.
    • test_render_skips_when_pending_queue_is_empty: Verifies render() outputs nothing when there are no pending connector approval requests.
    • test_render_outputs_singular_and_plural_messages_with_links: Verifies singular and plural notice copy along with the review and nonce-protected dismiss links.
    • test_maybe_handle_dismiss_bails_without_query_arg: Verifies maybe_handle_dismiss() bails when wpai_ca_notice_dismiss is absent.
    • test_maybe_handle_dismiss_bails_without_manage_options: Verifies maybe_handle_dismiss() bails when the user lacks manage_options.
    • test_maybe_handle_dismiss_bails_with_invalid_nonce: Verifies maybe_handle_dismiss() bails when the nonce is invalid.
    • test_maybe_handle_dismiss_stores_signature_and_silences_notice_until_queue_changes: Verifies that dismissing the notice stores the MD5 pending-queue signature in user meta, silences subsequent renders for the same queue, and re-displays the notice once a new pending request changes the queue signature.

Use of AI Tools

AI assistance: Yes
Model(s): Claude Opus 4.6
Used for: Auditing test coverage gaps in the Connector Approval subsystem and scaffolding test methods. All test cases, assertions, and coding standards compliance were reviewed and verified by me.

Testing Instructions

  1. Run PHP coding standards checks:
    composer lint
    vendor/bin/phpcs --standard=phpcs.xml.dist tests/Integration/Includes/Experiments/Connector_Approval/Admin_PageTest.php tests/Integration/Includes/Connector_Approval/Admin_NoticeTest.php
  2. Run PHPStan static analysis:
    composer phpstan
  3. Run the integration test suites:
    npm run test:php -- --filter=Admin_PageTest
    npm run test:php -- --filter=Admin_NoticeTest

Changelog Entry

Developer - Added unit and integration test coverage for Connector Approval Admin_Page and extended Admin_Notice tests.

Open WordPress Playground Preview

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.00%. Comparing base (19d5670) to head (3b26985).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1134      +/-   ##
=============================================
+ Coverage      81.67%   82.00%   +0.33%     
  Complexity      3103     3103              
=============================================
  Files            129      129              
  Lines          12334    12334              
=============================================
+ Hits           10074    10115      +41     
+ Misses          2260     2219      -41     
Flag Coverage Δ
unit 82.00% <ø> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@noruzzamans
noruzzamans marked this pull request as ready for review October 7, 2026 13:16
@noruzzamans
noruzzamans requested a review from a team October 7, 2026 13:16
@github-actions

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

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>

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

@dkotter dkotter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! While I appreciate increasing our test coverage, also want to ensure we're not just adding tests for the sake of adding tests and the tests we add are actually bringing value. I've flagged a few tests here that I think could likely be removed but let me know if you feel differently.

*
* @since x.x.x
*/
public function test_register_adds_admin_hooks(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I'm not sure what value this test is adding? I know we have similar tests in our codebase though I'd like to clean all of those up. Ideally we're testing that actual functionality works as expected and not just that certain hooks fire

*
* @since x.x.x
*/
public function test_register_adds_admin_hooks(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another one I'd question the value on having

*
* @since x.x.x
*/
public function test_url_returns_expected_admin_url(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any need for both this test and test_add_submenu_registers_tools_submenu_for_administrator?

@noruzzamans

Copy link
Copy Markdown
Contributor Author

Thanks @dkotter! That makes total sense — I completely agree that focusing on real functionality, permissions, and runtime behavior rather than shallow hook-registration checks brings much greater value and keeps the test suite clean and purposeful.

I've removed both hook-registration tests as well as the redundant URL test in commit 3b26985, keeping only the meaningful behavioral test coverage.

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