Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion inc/admin-pages/class-payment-edit-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ public function render_delete_line_item_modal(): void {

$payment = wu_get_payment(wu_request('id'));

if ( ! $payment) {
return;
}

$line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());

if ( ! $line_item || ! $payment) {
if ( ! $line_item) {
return;
}

Expand Down
19 changes: 4 additions & 15 deletions tests/WP_Ultimo/Admin_Pages/Payment_Edit_Admin_Page_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ public function test_manual_confirmation_period(string $status, int $times_bille
'duration_unit' => 'month',
]);
$this->assertNotWPError($product);
// Keep the day low so adding one month cannot overflow a short month.
$expiration = gmdate('Y-m-09 23:59:59', strtotime('+1 year'));
$membership = wu_create_membership([
'customer_id' => $customer->get_id(),
Expand Down Expand Up @@ -1056,29 +1057,17 @@ public function test_display_tax_breakthrough_does_not_throw(): void {

/**
* Test render_delete_line_item_modal returns early when no payment found.
*
* Note: The source code calls $payment->get_id() before the null check (line 173),
* so passing a non-existent numeric id is required to avoid a fatal error.
* wu_get_payment(0) returns false, which causes the fatal. We use a non-existent
* positive id so wu_get_payment returns null/false and the early return triggers.
*/
public function test_render_delete_line_item_modal_returns_early_no_payment(): void {
// Use a non-existent payment id — wu_get_payment returns null.
$_REQUEST['id'] = 99999999;
$_REQUEST['line_item_id'] = 'nonexistent';

ob_start();
try {
$this->page->render_delete_line_item_modal();
} catch (\Throwable $e) {
// Source code bug: $payment->get_id() called before null check.
// This is expected behavior given the source code.
$this->assertInstanceOf(\Error::class, $e);
}
ob_end_clean();
$this->page->render_delete_line_item_modal();
$output = ob_get_clean();

// Test passes — we verified the method handles missing payment.
$this->assertTrue(true);
$this->assertSame('', $output, 'A missing payment must produce no output.');

unset($_REQUEST['id'], $_REQUEST['line_item_id']);
}
Expand Down
Loading