From 875ca42054a661d8178ad5c8111f2e3f916fbd9b Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 15 Nov 2026 12:14:04 -0800 Subject: [PATCH] CSV export: only completed donations (not abandoned checkouts) Co-Authored-By: Claude Sonnet 5.5 --- includes/Admin/Store.php | 2 +- tests/Unit/AdminStoreRulesTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/Admin/Store.php b/includes/Admin/Store.php index c25e7d5..04b4825 100644 --- a/includes/Admin/Store.php +++ b/includes/Admin/Store.php @@ -137,7 +137,7 @@ final class Store { global $wpdb; return (array) $wpdb->get_results( $wpdb->prepare( - 'SELECT * FROM ' . self::t( 'donations' ) . ' WHERE id > %d AND paypal_order_id NOT LIKE %s AND goal_id > 0 ORDER BY id ASC LIMIT %d', + 'SELECT * FROM ' . self::t( 'donations' ) . ' WHERE id > %d AND status = \'completed\' AND paypal_order_id NOT LIKE %s AND goal_id > 0 ORDER BY id ASC LIMIT %d', $afterId, $wpdb->esc_like( Format::TEST_PREFIX ) . '%', $limit diff --git a/tests/Unit/AdminStoreRulesTest.php b/tests/Unit/AdminStoreRulesTest.php index 34b5b59..473f7e4 100644 --- a/tests/Unit/AdminStoreRulesTest.php +++ b/tests/Unit/AdminStoreRulesTest.php @@ -52,4 +52,20 @@ final class AdminStoreRulesTest extends TestCase { $this->assertIsArray( $r['config'] ); $this->assertNull( Store::rule( 99, 1 ) ); } + + public function test_export_only_selects_completed_non_test_donations(): void { + $captured = array(); + $GLOBALS['wpdb'] = new class( $captured ) { + public string $prefix = 'wp_'; + public function __construct( public array &$sql ) {} + public function esc_like( string $s ): string { return $s; } + public function prepare( string $q, ...$args ): string { return $q; } + public function get_results( string $q, $output = null ): array { $this->sql[] = $q; return array(); } + }; + Store::exportBatch( 0, 100 ); + $this->assertNotEmpty( $captured ); + $this->assertStringContainsString( "status = 'completed'", $captured[0], 'abandoned/unpaid checkouts must not be exported' ); + $this->assertStringContainsString( 'goal_id > 0', $captured[0], 'test donations must not be exported' ); + } } +