Repository navigation
Tests: Add unit test coverage for WP_Importer and get_cli_args() - #14327
huzaifaalmesbah wants to merge 2 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
🟡 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
left a comment
There was a problem hiding this comment.
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
|
Thanks, @lancewillett! Removed |
lancewillett
left a comment
There was a problem hiding this comment.
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
|
PR #14327 landed in https://core.trac.wordpress.org/changeset/64454 |
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
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

Description
Adds tests for the
WP_Importerbase class andget_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 stricttruemakes a HEAD request), Basic authorization only with both credentials, the bumped 60 second timeout, and using a safe request;bump_request_timeout(),min_whitespace()andstop_the_insanity(), which restores the query log and action counts infinally;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
npm run test:php -- --filter 'Tests_Admin_wpImporter'npm run test:php -- --filter 'Tests_Admin_wpImporter' -c tests/phpunit/multisite.xmlnpm run test:php -- --filter 'Tests_Admin_wpImporter' --order-by=randomnpm run test:php -- --group adminnode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/wpImporter.phpTrac 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.