[468] Improves test coverage and reliability#825
[468] Improves test coverage and reliability#825nimesh-xecurify wants to merge 10 commits intoWordPress:masterfrom
Conversation
Adds extensive unit tests across various core functionalities and provider methods to increase overall code coverage. Enhances the test suite's robustness by introducing a redirect interception mechanism and refining cookie-blocking assertions, preventing test termination and ensuring precise verification. Excludes trivial methods from code coverage reports where direct testing is impractical or unnecessary.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Addresses #468 |
There was a problem hiding this comment.
Pull request overview
This PR increases the Two-Factor plugin’s automated test coverage and improves test reliability around redirect/exit behavior and cookie-blocking assertions, while excluding a few trivial methods from coverage reporting.
Changes:
- Added/expanded unit tests for core flows and multiple provider behaviors (Email, TOTP, base Provider).
- Improved test-suite robustness by intercepting redirects to avoid
exit()terminating the test process, and refined assertions around auth-cookie blocking. - Marked trivial/unreachable-to-test methods (e.g., simple output/constructors) with
@codeCoverageIgnore.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
tests/providers/class-two-factor-totp.php |
Adds reflection-based tests for Two_Factor_Totp::pad_secret. |
tests/providers/class-two-factor-provider.php |
Adds tests for provider key/labels/support checks and base uninstall methods. |
tests/providers/class-two-factor-email.php |
Improves email token tests and adds coverage for additional Email provider behaviors. |
tests/class-two-factor-core.php |
Adds redirect interception helper and many new core tests; refines cookie-block assertions. |
providers/class-two-factor-provider.php |
Excludes print_label() from coverage reporting. |
providers/class-two-factor-email.php |
Excludes the Email provider constructor from coverage reporting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@nimesh-xecurify thank you very much for the PR! Can you check the copilot comments? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
tests/providers/class-two-factor-email.php:174
- This test extracts the token by matching an English substring from a translatable email message ("verification code below"). That makes the test locale-sensitive and brittle to copy changes; consider capturing the $token via the two_factor_token_email_message filter (it receives $message, $token, $user_id) or matching the token line structurally (e.g., digits between blank lines) instead of depending on the translated sentence.
$pattern = '/verification code below:\n\n(\d+)/';
$content = $GLOBALS['phpmailer']->Body;
$this->assertGreaterThan( 0, preg_match( $pattern, $content, $match ) );
$this->assertTrue( $this->provider->validate_token( $user->ID, $match[1] ) );
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Ensures anonymous functions are properly removed from hooks in tests. Adjusts filter return values and assertions for greater clarity and accuracy. Corrects a minor typo in a test assertion message.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Enhances several tests to be more robust and accurately reflect method behavior. - Improves the check for plugin cookie blocking by explicitly verifying the `__return_false` callback. - Ensures a clean test environment for `collect_auth_cookie_tokens` by resetting its static property and directly asserting its populated state. - Corrects the `is_supported_for_user` test to check for global provider registration, aligning with the method's intended logic.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ensures proper cleanup of authentication cookie filters after tests to prevent unintended side effects on subsequent test runs. Updates email verification regex to use a universal newline matcher, improving test robustness against varied email content formatting.
Applies process isolation and global state disabling to the API authentication test. This prevents global state contamination and ensures consistent test results. Adds a guard to prevent redefinition of the `XMLRPC_REQUEST` constant, making the test more robust and reliable when running in various environments or alongside other tests that might set the constant.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
What?
Improves test coverage and reliability
Fixes #468
How?
Adds extensive unit tests across various core functionalities and provider methods to increase overall code coverage.
Enhances the test suite's robustness by introducing a redirect interception mechanism and refining cookie-blocking assertions, preventing test termination and ensuring precise verification.
Excludes trivial methods from code coverage reports where direct testing is impractical or unnecessary.
Screenshots or screencast
Current Test Coverage

New Test Coverage

Changelog Entry
Usage of AI Tools
Used Claude Code to generate new tests (and fix some existing issues related to code coverage), post manual review at each step.