Skip to content

Tests: Add unit test coverage for WP_Importer and get_cli_args() - #14327

Closed
huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/wp-importer
Closed

huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/wp-importer

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds tests for the WP_Importer base class and get_cli_args(), which had no direct coverage. The tests cover:

  • get_imported_posts(): mapping permalinks to post IDs for one importer and blog, reading past the first 100-row chunk, and an empty result;
  • count_imported_posts(): counting only the given importer and blog;
  • get_imported_comments(): mapping source comment IDs only for the given blog;
  • set_blog(): a numeric ID on single site, and on multisite switching to the blog resolved by ID or by URL with and without a scheme;
  • set_user(): setting the current user by ID or login;
  • cmpr_strlen(): sorting the longest string first;
  • get_page(): request method (only a strict true makes a HEAD request), Basic authorization only with both credentials, the bumped 60 second timeout, and using a safe request;
  • bump_request_timeout(), min_whitespace() and stop_the_insanity(), which restores the query log and action counts in finally;
  • is_user_over_quota() on single site and, with filtered space values, on multisite, including the message it prints;
  • get_cli_args(): long options with and without values, values after options, combined short options, later options overriding earlier ones, empty and zero values, and a non-array $_SERVER['argv'].

Exit paths are not covered because they end the test process. $_SERVER['argv'] is restored after each test.

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_wpImporter'
  2. Run them on multisite:
    npm run test:php -- --filter 'Tests_Admin_wpImporter' -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter 'Tests_Admin_wpImporter' --order-by=random
  4. Run the admin group:
    npm run test:php -- --group admin
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/wpImporter.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 16, 2026 10:26
@github-actions

github-actions Bot commented Oct 16, 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.

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

Props huzaifaalmesbah, lancewillett.

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

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

Invalid coverage annotations must be corrected for coverage-enabled PHPUnit runs.

1 open finding
What changed in this PR

Adds direct PHPUnit coverage for WordPress’s importer base class and CLI argument parser without changing production code.

Changes:

  • Tests importer mappings, site and user selection, HTTP requests, quotas, and utility methods.
  • Covers CLI option parsing and restores modified test state.
File Description
tests/​phpunit/​tests/​admin/​wpImporter.php Adds tests for WP_Importer and get_cli_args().

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

* @group admin
* @group import
*
* @coversDefaultClass WP_Importer

@lancewillett lancewillett 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.

Please remove @coversDefaultClass WP_Importer and qualify the importer method annotations as @covers WP_Importer::method, keeping @covers ::get_cli_args for the global function.

The class default currently makes both get_cli_args() annotations resolve to the nonexistent WP_Importer::get_cli_args. I reproduced InvalidCoversTargetException using PHPUnit’s coverage parser. Ordinary test runs pass, so green CI does not catch this.

Otherwise, the unit-test audit, randomized single-site and multisite tests, and PHPCS passed.

AI review · gpt-6

@huzaifaalmesbah

Copy link
Copy Markdown
Member Author

Thanks, @lancewillett! Removed @coversDefaultClass and qualified the method annotations as @covers WP_Importer::method, keeping @covers ::get_cli_args for the global function (24cdaf2). All covers targets now resolve with PHPUnit's coverage parser, which previously threw InvalidCoversTargetException for both get_cli_args() tests.

@rejaulalomkhan rejaulalomkhan 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.

Re-tested 24cdaf2 locally — confirmed all @Covers targets resolve cleanly with 0 exceptions now, and all tests pass.

@lancewillett lancewillett 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.

Reviewed the tests against the implementation and existing coverage, including the unit-tests audit. No blocking findings. The affected classes passed locally in randomized order on single site (36 tests) and multisite (39 tests); PHPCS and current CI pass.

The earlier coverage-annotation issue is fixed: class methods and the global get_cli_args() function now have the correct targets.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 17, 2026
Verify importer mappings, blog and user selection, request options, quota handling, and command-line argument parsing. Cover the 100-row boundary in `get_imported_posts()`.

Developed in: #14327

Props huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64454 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 17, 2026
Verify importer mappings, blog and user selection, request options, quota handling, and command-line argument parsing. Cover the 100-row boundary in `get_imported_posts()`.

Developed in: WordPress/wordpress-develop#14327

Props huzaifaalmesbah.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64454


git-svn-id: http://core.svn.wordpress.org/trunk@63604 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants