close
Skip to content

[468] Improves test coverage and reliability#825

Open
nimesh-xecurify wants to merge 10 commits intoWordPress:masterfrom
nimesh-xecurify:improve-test-coverage
Open

[468] Improves test coverage and reliability#825
nimesh-xecurify wants to merge 10 commits intoWordPress:masterfrom
nimesh-xecurify:improve-test-coverage

Conversation

@nimesh-xecurify
Copy link

@nimesh-xecurify nimesh-xecurify commented Mar 9, 2026

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
image

New Test Coverage
image

Changelog Entry

Changed / Fixed - Improved Test Coverage.

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.

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.
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

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: nimesh-xecurify <nimeshatxecurify@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: iandunn <iandunn@git.wordpress.org>

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

@nimesh-xecurify
Copy link
Author

Addresses #468

@nimesh-xecurify nimesh-xecurify changed the title Improves test coverage and reliability [468] Improves test coverage and reliability Mar 9, 2026
@masteradhoc masteradhoc added this to the 0.16.0 milestone Mar 9, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@masteradhoc
Copy link
Collaborator

@nimesh-xecurify thank you very much for the PR! Can you check the copilot comments?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

nimesh-xecurify and others added 3 commits March 12, 2026 10:56
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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

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.

Test coverage seems low

3 participants