44namespace WooCommerce \PayPalCommerce \StoreSync \CartValidation ;
55
66use WooCommerce \PayPalCommerce \StoreSync \Schema \PayPalCart ;
7- use WooCommerce \PayPalCommerce \StoreSync \Validation \ValidationIssue ;
8- use WooCommerce \PayPalCommerce \TestCase ;
9-
107use function Brain \Monkey \Functions \when ;
118
129/**
1310 * @covers \WooCommerce\PayPalCommerce\StoreSync\CartValidation\CurrencyValidator
1411 */
15- class CurrencyValidatorTest extends TestCase {
12+ class CurrencyValidatorTest extends ValidationTest {
1613
1714 private CurrencyValidator $ validator ;
1815
@@ -51,11 +48,9 @@ public function test_validate_detects_mixed_currencies(): void {
5148
5249 $ this ->assertIsArray ( $ result );
5350 $ this ->assertCount ( 1 , $ result );
54- $ this ->assertInstanceOf ( ValidationIssue::class, $ result [0 ] );
5551
5652 $ issue_data = $ result [0 ]->to_array ();
57- $ this ->assertStringContainsString ( 'Mixed currencies detected ' , $ issue_data ['message ' ] );
58- $ this ->assertSame ( 'items[1].price.currency_code ' , $ issue_data ['field ' ] );
53+ $ this ->assertValidationIssue ( $ issue_data , 'PRICING_ERROR ' , 'BUSINESS_RULE ' , 'items[1].price.currency_code ' , 'Mixed currencies detected ' );
5954 }
6055
6156 public function test_validate_detects_store_currency_mismatch (): void {
@@ -72,12 +67,9 @@ public function test_validate_detects_store_currency_mismatch(): void {
7267
7368 $ this ->assertIsArray ( $ result );
7469 $ this ->assertCount ( 1 , $ result );
75- $ this ->assertInstanceOf ( ValidationIssue::class, $ result [0 ] );
7670
7771 $ issue_data = $ result [0 ]->to_array ();
78- $ this ->assertStringContainsString ( 'Cart currency EUR does not match store currency USD ' , $ issue_data ['message ' ] );
79- $ this ->assertStringContainsString ( 'This store only accepts payments in USD ' , $ issue_data ['user_message ' ] );
80- $ this ->assertSame ( 'items[0].price.currency_code ' , $ issue_data ['field ' ] );
72+ $ this ->assertValidationIssue ( $ issue_data , 'PRICING_ERROR ' , 'BUSINESS_RULE ' , 'items[0].price.currency_code ' , 'Cart currency EUR does not match store currency USD ' );
8173 }
8274
8375 public function test_validate_returns_null_for_empty_cart (): void {
@@ -165,13 +157,9 @@ public function test_detects_mismatch_skipping_empty_items(): void {
165157
166158 $ this ->assertIsArray ( $ result );
167159 $ this ->assertCount ( 1 , $ result );
168- $ this ->assertInstanceOf ( ValidationIssue::class, $ result [0 ] );
169160
170161 $ issue_data = $ result [0 ]->to_array ();
171- $ this ->assertStringContainsString ( 'Mixed currencies detected ' , $ issue_data ['message ' ] );
172- $ this ->assertStringContainsString ( 'EUR ' , $ issue_data ['message ' ] );
173- $ this ->assertStringContainsString ( 'USD ' , $ issue_data ['message ' ] );
174- $ this ->assertSame ( 'items[2].price.currency_code ' , $ issue_data ['field ' ] );
162+ $ this ->assertValidationIssue ( $ issue_data , 'PRICING_ERROR ' , 'BUSINESS_RULE ' , 'items[2].price.currency_code ' , 'Mixed currencies detected ' );
175163 }
176164
177165 public function test_store_mismatch_points_to_correct_index (): void {
@@ -203,11 +191,9 @@ public function test_store_mismatch_points_to_correct_index(): void {
203191
204192 $ this ->assertIsArray ( $ result );
205193 $ this ->assertCount ( 1 , $ result );
206- $ this ->assertInstanceOf ( ValidationIssue::class, $ result [0 ] );
207194
208195 $ issue_data = $ result [0 ]->to_array ();
209- $ this ->assertStringContainsString ( 'Cart currency EUR does not match store currency USD ' , $ issue_data ['message ' ] );
210- $ this ->assertSame ( 'items[1].price.currency_code ' , $ issue_data ['field ' ] );
196+ $ this ->assertValidationIssue ( $ issue_data , 'PRICING_ERROR ' , 'BUSINESS_RULE ' , 'items[1].price.currency_code ' , 'Cart currency EUR does not match store currency USD ' );
211197 }
212198
213199 public function test_mixed_currency_prevents_store_check (): void {
@@ -224,10 +210,9 @@ public function test_mixed_currency_prevents_store_check(): void {
224210
225211 $ this ->assertIsArray ( $ result );
226212 $ this ->assertCount ( 1 , $ result );
227- $ this ->assertInstanceOf ( ValidationIssue::class, $ result [0 ] );
228213
229214 $ issue = $ result [0 ]->to_array ();
230- $ this ->assertStringContainsString ( ' Mixed currencies detected ', $ issue [ ' message ' ] );
215+ $ this ->assertValidationIssue ( $ issue , ' PRICING_ERROR ' , ' BUSINESS_RULE ' , null , ' Mixed currencies detected ' );
231216 }
232217
233218 /**
0 commit comments