|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * These tests make assertions against class WC_Stripe_Express_Checkout_Helper. |
| 5 | + * |
| 6 | + * @package WooCommerce_Stripe/Tests/WC_Stripe_Express_Checkout_Helper |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * WC_Stripe_Express_Checkout_Helper class. |
| 11 | + */ |
| 12 | +class WC_Stripe_Express_Checkout_Helper_Test extends WP_UnitTestCase { |
| 13 | + public function set_up() { |
| 14 | + parent::set_up(); |
| 15 | + |
| 16 | + $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); |
| 17 | + $stripe_settings['enabled'] = 'yes'; |
| 18 | + $stripe_settings['testmode'] = 'yes'; |
| 19 | + $stripe_settings['test_publishable_key'] = 'pk_test_key'; |
| 20 | + $stripe_settings['test_secret_key'] = 'sk_test_key'; |
| 21 | + WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Test should_show_express_checkout_button, tax logic. |
| 26 | + */ |
| 27 | + public function test_hides_ece_if_cannot_compute_taxes() { |
| 28 | + $wc_stripe_ece_helper_mock = $this->createPartialMock( |
| 29 | + WC_Stripe_Express_Checkout_Helper::class, |
| 30 | + [ |
| 31 | + 'is_product', |
| 32 | + 'allowed_items_in_cart', |
| 33 | + 'should_show_ece_on_cart_page', |
| 34 | + 'should_show_ece_on_checkout_page', |
| 35 | + ] |
| 36 | + ); |
| 37 | + $wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'is_product' )->willReturn( false ); |
| 38 | + $wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'allowed_items_in_cart' )->willReturn( true ); |
| 39 | + $wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'should_show_ece_on_cart_page' )->willReturn( true ); |
| 40 | + $wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'should_show_ece_on_checkout_page' )->willReturn( true ); |
| 41 | + $wc_stripe_ece_helper_mock->testmode = true; |
| 42 | + if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
| 43 | + define( 'WOOCOMMERCE_CHECKOUT', true ); |
| 44 | + } |
| 45 | + |
| 46 | + // Create virtual product and add to cart. |
| 47 | + $virtual_product = WC_Helper_Product::create_simple_product(); |
| 48 | + $virtual_product->set_virtual( true ); |
| 49 | + $virtual_product->save(); |
| 50 | + |
| 51 | + WC()->session->init(); |
| 52 | + WC()->cart->add_to_cart( $virtual_product->get_id(), 1 ); |
| 53 | + |
| 54 | + // Hide if cart has virtual product and tax is based on shipping or billing address. |
| 55 | + update_option( 'woocommerce_tax_based_on', 'billing' ); |
| 56 | + $this->assertFalse( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); |
| 57 | + |
| 58 | + update_option( 'woocommerce_tax_based_on', 'shipping' ); |
| 59 | + $this->assertFalse( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); |
| 60 | + |
| 61 | + // Do not hide if taxes are not based on customer billing or shipping address. |
| 62 | + update_option( 'woocommerce_tax_based_on', 'base' ); |
| 63 | + $this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); |
| 64 | + |
| 65 | + // Do not hide if cart requires shipping. |
| 66 | + $shippable_product = WC_Helper_Product::create_simple_product(); |
| 67 | + WC()->cart->add_to_cart( $shippable_product->get_id(), 1 ); |
| 68 | + $this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); |
| 69 | + } |
| 70 | +} |
0 commit comments