@@ -189,6 +189,115 @@ public function test_venmo_enabled_when_setting_is_true()
189189 $ this ->assertNotContains ('venmo ' , $ sut ->sources ('checkout-block ' ));
190190 }
191191
192+ /**
193+ * Free-trial cart on classic checkout with ACDC enabled: 'card' must stay enabled
194+ * (otherwise paypal.CardFields() reports ineligible and the card iframes never
195+ * render over the stock WooCommerce inputs).
196+ */
197+ public function test_free_trial_classic_checkout_with_acdc_keeps_card_enabled ()
198+ {
199+ $ this ->dcc_configuration ->shouldReceive ('is_acdc_enabled ' )->andReturn (true );
200+ $ this ->dcc_configuration ->shouldReceive ('is_bcdc_enabled ' )->andReturn (false );
201+
202+ $ sut = $ this ->makeFreeTrialSut (
203+ [
204+ 'card ' => 'Credit or debit cards ' ,
205+ 'paypal ' => 'PayPal ' ,
206+ 'venmo ' => 'Venmo ' ,
207+ ],
208+ 'US '
209+ );
210+
211+ $ this ->setWooCommerceFunctionMocks ();
212+ when ('is_checkout ' )->justReturn (true );
213+
214+ $ this ->assertNotContains ('card ' , $ sut ->sources ('checkout ' ));
215+ }
216+
217+ /**
218+ * Free-trial cart on classic checkout with BCDC enabled: 'card' stays enabled
219+ * (pre-existing behavior, kept intact by the refactor).
220+ */
221+ public function test_free_trial_classic_checkout_with_bcdc_keeps_card_enabled ()
222+ {
223+ $ this ->dcc_configuration ->shouldReceive ('is_acdc_enabled ' )->andReturn (false );
224+ $ this ->dcc_configuration ->shouldReceive ('is_bcdc_enabled ' )->andReturn (true );
225+
226+ $ sut = $ this ->makeFreeTrialSut (
227+ [
228+ 'card ' => 'Credit or debit cards ' ,
229+ 'paypal ' => 'PayPal ' ,
230+ ],
231+ 'US '
232+ );
233+
234+ $ this ->setWooCommerceFunctionMocks ();
235+ when ('is_checkout ' )->justReturn (true );
236+
237+ $ this ->assertNotContains ('card ' , $ sut ->sources ('checkout ' ));
238+ }
239+
240+ /**
241+ * Free-trial cart on block checkout with ACDC enabled: 'card' stays disabled
242+ * (block ACDC uses the WC Blocks integration, not the 'card' SDK funding source).
243+ */
244+ public function test_free_trial_block_checkout_with_acdc_disables_card ()
245+ {
246+ $ this ->dcc_configuration ->shouldReceive ('is_acdc_enabled ' )->andReturn (true );
247+ $ this ->dcc_configuration ->shouldReceive ('is_bcdc_enabled ' )->andReturn (false );
248+
249+ $ sut = $ this ->makeFreeTrialSut (
250+ [
251+ 'card ' => 'Credit or debit cards ' ,
252+ 'paypal ' => 'PayPal ' ,
253+ ],
254+ 'US '
255+ );
256+
257+ $ this ->setWooCommerceFunctionMocks ();
258+ when ('is_checkout ' )->justReturn (true );
259+
260+ $ this ->assertContains ('card ' , $ sut ->sources ('checkout-block ' ));
261+ }
262+
263+ /**
264+ * Free-trial cart on classic checkout with neither ACDC nor BCDC: 'card' disabled
265+ * (no card flow active).
266+ */
267+ public function test_free_trial_classic_checkout_no_card_flow_disables_card ()
268+ {
269+ $ this ->dcc_configuration ->shouldReceive ('is_acdc_enabled ' )->andReturn (false );
270+ $ this ->dcc_configuration ->shouldReceive ('is_bcdc_enabled ' )->andReturn (false );
271+
272+ $ sut = $ this ->makeFreeTrialSut (
273+ [
274+ 'card ' => 'Credit or debit cards ' ,
275+ 'paypal ' => 'PayPal ' ,
276+ ],
277+ 'US '
278+ );
279+
280+ $ this ->setWooCommerceFunctionMocks ();
281+ when ('is_checkout ' )->justReturn (true );
282+
283+ $ this ->assertContains ('card ' , $ sut ->sources ('checkout ' ));
284+ }
285+
286+ /**
287+ * Builds a DisabledFundingSources whose is_free_trial_cart() is forced to true,
288+ * so the free-trial branch can be tested without bootstrapping WooCommerce
289+ * Subscriptions and WC()->cart.
290+ */
291+ private function makeFreeTrialSut (array $ funding_sources , string $ country ): DisabledFundingSources
292+ {
293+ return new class ($ this ->settings_provider , $ funding_sources , $ this ->dcc_configuration , $ country ) extends DisabledFundingSources {
294+ protected function is_free_trial_cart (): bool
295+ {
296+ return true ;
297+ }
298+ };
299+ }
300+
192301 /**
193302 * Set up common WooCommerce function mocks
194303 */
0 commit comments