Skip to content

GH#713: write unit tests for Base_PayPal_Gateway#717

Merged
superdav42 merged 2 commits intomainfrom
test/gh713-base-paypal-gateway-tests
Mar 31, 2026
Merged

GH#713: write unit tests for Base_PayPal_Gateway#717
superdav42 merged 2 commits intomainfrom
test/gh713-base-paypal-gateway-tests

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Mar 31, 2026

Summary

Implements comprehensive unit tests for the Base_PayPal_Gateway class, achieving 100% code coverage (48/48 lines).

Changes

  • Created tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php with 33 tests
  • Tests cover all public and protected methods:
    • URL generation (sandbox vs live mode for payments and subscriptions)
    • Subscription ID type detection (REST API I- prefix vs legacy NVP)
    • Partner attribution header injection (ULTIMATE_SP_PPCP BN code)
    • Subscription description truncation (127 chars) and HTML entity decoding
    • Site actions hook integration with membership gateway matching
    • Support flags (supports_recurring, supports_amount_update)
    • Test mode switching and property access

Test Results

OK (33 tests, 47 assertions)

Code Coverage:
  WP_Ultimo\Gateways\Base_PayPal_Gateway
    Methods: 100.00% (12/12)
    Lines:   100.00% (48/48)

Verification

All tests pass in multisite environment:

WP_TESTS_MULTISITE=1 vendor/bin/phpunit --filter Base_PayPal_Gateway_Test

Closes #713


aidevops.sh v3.5.468 plugin for OpenCode v1.3.0 with claude-sonnet-4-5 spent 4m and 11,869 tokens on this as a headless worker.

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for PayPal gateway functionality, including URL generation for both sandbox and production environments, REST and legacy subscription ID support, partner attribution header injection, subscription description formatting with entity decoding, and site action integration for managing PayPal transactions with appropriate links and icons.

- Create Base_PayPal_Gateway_Test.php with 33 tests covering all public and protected methods
- Test URL generation (sandbox vs live mode for payments and subscriptions)
- Test subscription ID type detection (REST API I- prefix vs legacy NVP)
- Test partner attribution header injection
- Test subscription description truncation and HTML entity decoding
- Test site actions hook integration with membership gateway matching
- Test support flags (recurring, amount_update)
- Achieve 100% code coverage (48/48 lines) for Base_PayPal_Gateway class

Closes #713
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

A new comprehensive test file was added for the Base_PayPal_Gateway class, including a concrete stub implementation and test suite covering URL generation, subscription handling, partner attribution headers, and site action hook behavior.

Changes

Cohort / File(s) Summary
Base PayPal Gateway Test Suite
tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php
Added 657 lines containing Base_PayPal_Gateway_Stub (concrete subclass with public wrappers for protected methods) and Base_PayPal_Gateway_Test test class with 20+ test methods covering: recurring/amount-update support, sandbox/live URL switching, subscription URL generation for REST vs. NVP profiles, subscription description truncation and HTML entity decoding, REST subscription ID detection (case-sensitive I- prefix matching), partner attribution header injection, and site actions hook behavior with correct labels, icons, and hrefs based on test_mode.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

needs-review-fixes

Poem

🐰 With whiskers twitching, tests now written,
PayPal's base class is now smitten!
URLs tested, headers checked,
Subscriptions verified, no defects!
Coverage blooms where none existed before. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR achieves 100% coverage (48/48 lines) with 33 tests, but only covers 6 of the ~300-line class. The acceptance criteria require tests for IPN handling, webhook verification, payment status processing, and refund processing, which are not clearly documented as covered. Verify that the test suite covers IPN handling, webhook verification, payment status processing, and refund processing as required by issue #713 acceptance criteria.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding unit tests for the Base_PayPal_Gateway class, with clear reference to the related issue #713.
Out of Scope Changes check ✅ Passed The PR adds only the test file and stub class as required by the linked issue, with no unrelated or extraneous changes beyond the scope of adding comprehensive unit tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/gh713-base-paypal-gateway-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php (3)

649-656: Use assertNotFalse() instead of assertTrue() for has_filter() return value.

has_filter() returns the lowest priority (integer, e.g., 10) if callbacks exist, or false if none. Using assertTrue() works because 10 is truthy, but it's semantically misleading. The assertion should reflect the actual return type.

🧹 Suggested fix
 	public function test_hooks_registers_site_actions_filter(): void {
 		// Remove any existing hooks first.
 		remove_all_filters( 'wu_element_get_site_actions' );

 		$this->gateway->hooks();

-		$this->assertTrue( has_filter( 'wu_element_get_site_actions' ) );
+		$this->assertNotFalse( has_filter( 'wu_element_get_site_actions' ) );
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php` around lines 649 -
656, The test test_hooks_registers_site_actions_filter uses assertTrue on
has_filter, but has_filter returns an int priority or false; update the
assertion to assertNotFalse(has_filter('wu_element_get_site_actions')) so the
test correctly checks that a filter exists; locate the test method
test_hooks_registers_site_actions_filter in Base_PayPal_Gateway_Test and replace
the assertTrue call with assertNotFalse while keeping the remove_all_filters and
$this->gateway->hooks() calls unchanged.

587-604: Log tests only verify no exceptions—consider adding behavior verification.

The tests acknowledge the limitation but provide no actual verification of logging behavior. If this is intentional due to difficulty mocking global functions, consider adding a comment noting this as a coverage gap or using a filter/action to intercept log calls if one exists.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php` around lines 587 -
604, The tests test_log_calls_wu_log_add_with_default_level and
test_log_calls_wu_log_add_with_custom_level only assert no exception and don't
verify logging behavior; either add a clear comment noting this is an accepted
coverage gap due to the unmockable global wu_log_add, or modify the tests to
verify behavior by intercepting the log (e.g., attach a WP filter/action or
wrapper that your Base_PayPal_Gateway::public_log uses) and assert it received
the expected message/level when calling public_log on the gateway; update the
test names/comments to reflect which approach you chose and reference the
public_log method as the target to hook or document.

17-19: Unused import: Site class is not referenced in this file.

The Site model is imported but never used in the test file. Consider removing it to keep imports clean.

🧹 Suggested fix
 use WP_Ultimo\Models\Customer;
 use WP_Ultimo\Models\Membership;
-use WP_Ultimo\Models\Site;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php` around lines 17 - 19,
The import for the Site model is unused in Base_PayPal_Gateway_Test: remove the
line "use WP_Ultimo\Models\Site;" from the top of the test file (while keeping
the existing imports for Customer and Membership) and run the tests to confirm
there are no references to Site elsewhere in the class.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php`:
- Around line 649-656: The test test_hooks_registers_site_actions_filter uses
assertTrue on has_filter, but has_filter returns an int priority or false;
update the assertion to
assertNotFalse(has_filter('wu_element_get_site_actions')) so the test correctly
checks that a filter exists; locate the test method
test_hooks_registers_site_actions_filter in Base_PayPal_Gateway_Test and replace
the assertTrue call with assertNotFalse while keeping the remove_all_filters and
$this->gateway->hooks() calls unchanged.
- Around line 587-604: The tests test_log_calls_wu_log_add_with_default_level
and test_log_calls_wu_log_add_with_custom_level only assert no exception and
don't verify logging behavior; either add a clear comment noting this is an
accepted coverage gap due to the unmockable global wu_log_add, or modify the
tests to verify behavior by intercepting the log (e.g., attach a WP
filter/action or wrapper that your Base_PayPal_Gateway::public_log uses) and
assert it received the expected message/level when calling public_log on the
gateway; update the test names/comments to reflect which approach you chose and
reference the public_log method as the target to hook or document.
- Around line 17-19: The import for the Site model is unused in
Base_PayPal_Gateway_Test: remove the line "use WP_Ultimo\Models\Site;" from the
top of the test file (while keeping the existing imports for Customer and
Membership) and run the tests to confirm there are no references to Site
elsewhere in the class.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32c6c431-aa12-4af5-9e98-00f5e5d2d707

📥 Commits

Reviewing files that changed from the base of the PR and between a895c8c and 8fa2b31.

📒 Files selected for processing (1)
  • tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Performance Test Results

Performance test results for 1151206 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.83 MB 862.00 ms (-28.00 ms / -3% ) 166.50 ms 1097.00 ms (+27.50 ms / +3% ) 2088.00 ms (+46.00 ms / +2% ) 2002.45 ms (+41.25 ms / +2% ) 90.35 ms
1 56 49.02 MB 943.00 ms 151.00 ms (+4.00 ms / +3% ) 1093.50 ms 2116.00 ms (+50.00 ms / +2% ) 2032.45 ms (+52.10 ms / +3% ) 83.30 ms

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit 5d4bea5 into main Mar 31, 2026
11 checks passed
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(gateway): write unit tests for Base_PayPal_Gateway (inc/gateways/class-base-paypal-gateway.php — 0% coverage, ~300 lines)

1 participant