55
66use WooCommerce \PayPalCommerce \StoreSync \Helper \ProductManager ;
77use WooCommerce \PayPalCommerce \StoreSync \Schema \PayPalCart ;
8- use WooCommerce \PayPalCommerce \StoreSync \Validation \InvalidAddress ;
9- use WooCommerce \PayPalCommerce \StoreSync \Validation \ShippingUnavailable ;
8+ use WooCommerce \PayPalCommerce \StoreSync \Validation \ValidationIssue ;
109use WooCommerce \PayPalCommerce \TestCase ;
1110
1211use function Brain \Monkey \Functions \when ;
@@ -65,7 +64,7 @@ public function test_validate_detects_disallowed_country(): void {
6564
6665 $ this ->assertIsArray ( $ result );
6766 $ this ->assertCount ( 1 , $ result );
68- $ this ->assertInstanceOf ( ShippingUnavailable ::class, $ result [0 ] );
67+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
6968
7069 $ issue_data = $ result [0 ]->to_array ();
7170 $ this ->assertStringContainsString ( 'Shipping to FR is not available ' , $ issue_data ['message ' ] );
@@ -79,6 +78,9 @@ public function test_validate_returns_null_for_cart_without_shipping_address():
7978 array ( 'US ' => 'United States ' )
8079 );
8180
81+ $ this ->product_manager ->shouldReceive ( 'find_product ' )
82+ ->andReturn ( null );
83+
8284 $ cart = PayPalCart::from_array (
8385 array (
8486 'items ' => array (
@@ -134,7 +136,7 @@ public function test_validate_detects_missing_street_address(): void {
134136
135137 $ this ->assertIsArray ( $ result );
136138 $ this ->assertCount ( 1 , $ result );
137- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [0 ] );
139+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
138140
139141 $ issue_data = $ result [0 ]->to_array ();
140142 $ this ->assertStringContainsString ( 'missing street address ' , $ issue_data ['message ' ] );
@@ -159,7 +161,7 @@ public function test_validate_detects_missing_city(): void {
159161
160162 $ this ->assertIsArray ( $ result );
161163 $ this ->assertCount ( 1 , $ result );
162- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [0 ] );
164+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
163165
164166 $ issue_data = $ result [0 ]->to_array ();
165167 $ this ->assertStringContainsString ( 'missing city ' , $ issue_data ['message ' ] );
@@ -184,7 +186,7 @@ public function test_validate_detects_missing_postal_code(): void {
184186
185187 $ this ->assertIsArray ( $ result );
186188 $ this ->assertCount ( 1 , $ result );
187- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [0 ] );
189+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
188190
189191 $ issue_data = $ result [0 ]->to_array ();
190192 $ this ->assertStringContainsString ( 'missing postal code ' , $ issue_data ['message ' ] );
@@ -207,9 +209,9 @@ public function test_validate_detects_multiple_missing_fields(): void {
207209
208210 $ this ->assertIsArray ( $ result );
209211 $ this ->assertCount ( 3 , $ result );
210- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [0 ] );
211- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [1 ] );
212- $ this ->assertInstanceOf ( InvalidAddress ::class, $ result [2 ] );
212+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
213+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [1 ] );
214+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [2 ] );
213215 }
214216
215217 // Scenario 2: PO Box Restriction Tests
@@ -241,20 +243,22 @@ public function test_validate_detects_po_box_with_signature_required_items(): vo
241243
242244 $ this ->assertIsArray ( $ result );
243245 $ this ->assertCount ( 1 , $ result );
244- $ this ->assertInstanceOf ( ShippingUnavailable ::class, $ result [0 ] );
246+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
245247
246248 $ issue_data = $ result [0 ]->to_array ();
247249 $ this ->assertStringContainsString ( 'PO Box delivery not available ' , $ issue_data ['message ' ] );
248250 $ this ->assertStringContainsString ( 'signature confirmation ' , $ issue_data ['user_message ' ] );
249251 $ this ->assertSame ( 'shipping_address ' , $ issue_data ['field ' ] );
250252
251- // Verify context
253+ // Verify context (context is a list of IssueContext::to_array() results)
252254 $ this ->assertArrayHasKey ( 'context ' , $ issue_data );
253- $ this ->assertArrayHasKey ( 'restricted_items ' , $ issue_data ['context ' ] );
254- $ this ->assertArrayHasKey ( 'restriction_reason ' , $ issue_data ['context ' ] );
255- $ this ->assertArrayHasKey ( 'po_box_detected ' , $ issue_data ['context ' ] );
256- $ this ->assertSame ( 'signature_required ' , $ issue_data ['context ' ]['restriction_reason ' ] );
257- $ this ->assertTrue ( $ issue_data ['context ' ]['po_box_detected ' ] );
255+ $ this ->assertCount ( 1 , $ issue_data ['context ' ] );
256+ $ context = $ issue_data ['context ' ][0 ];
257+ $ this ->assertArrayHasKey ( 'restricted_items ' , $ context );
258+ $ this ->assertArrayHasKey ( 'restriction_reason ' , $ context );
259+ $ this ->assertArrayHasKey ( 'po_box_detected ' , $ context );
260+ $ this ->assertSame ( 'signature_required ' , $ context ['restriction_reason ' ] );
261+ $ this ->assertTrue ( $ context ['po_box_detected ' ] );
258262
259263 // Verify resolution_options
260264 $ this ->assertArrayHasKey ( 'resolution_options ' , $ issue_data );
@@ -340,7 +344,7 @@ public function test_validate_detects_po_box_with_dots_and_spaces(): void {
340344
341345 $ this ->assertIsArray ( $ result );
342346 $ this ->assertCount ( 1 , $ result );
343- $ this ->assertInstanceOf ( ShippingUnavailable ::class, $ result [0 ] );
347+ $ this ->assertInstanceOf ( ValidationIssue ::class, $ result [0 ] );
344348 }
345349
346350 public function test_validate_handles_product_not_found_for_signature_check (): void {
0 commit comments