10
10
* WC_Stripe_Express_Checkout_Helper_Test class.
11
11
*/
12
12
class WC_Stripe_Express_Checkout_Helper_Test extends WP_UnitTestCase {
13
+ private $ shipping_zone ;
14
+ private $ shipping_method ;
15
+
13
16
public function set_up () {
14
17
parent ::set_up ();
15
18
@@ -19,24 +22,37 @@ public function set_up() {
19
22
$ stripe_settings ['test_publishable_key ' ] = 'pk_test_key ' ;
20
23
$ stripe_settings ['test_secret_key ' ] = 'sk_test_key ' ;
21
24
WC_Stripe_Helper::update_main_stripe_settings ( $ stripe_settings );
25
+ }
26
+
27
+ public function tear_down () {
28
+ if ( $ this ->shipping_zone ) {
29
+ delete_option ( $ this ->shipping_method ->get_instance_option_key () );
30
+ $ this ->shipping_zone ->delete ();
31
+ }
22
32
33
+ parent ::tear_down ();
34
+ }
35
+
36
+ public function set_up_shipping_methods () {
23
37
// Add a shipping zone.
24
- $ zone = new WC_Shipping_Zone ();
25
- $ zone ->set_zone_name ( 'Worldwide ' );
26
- $ zone ->set_zone_order ( 1 );
27
- $ zone ->save ();
28
-
29
- $ flat_rate_id = $ zone ->add_shipping_method ( 'flat_rate ' );
30
- $ method = WC_Shipping_Zones::get_shipping_method ( $ flat_rate_id );
31
- $ option_key = $ method ->get_instance_option_key ();
32
- $ options ['cost ' ] = '5 ' ;
38
+ $ this -> shipping_zone = new WC_Shipping_Zone ();
39
+ $ this -> shipping_zone ->set_zone_name ( 'Worldwide ' );
40
+ $ this -> shipping_zone ->set_zone_order ( 1 );
41
+ $ this -> shipping_zone ->save ();
42
+
43
+ $ flat_rate_id = $ this -> shipping_zone ->add_shipping_method ( 'flat_rate ' );
44
+ $ this -> shipping_method = WC_Shipping_Zones::get_shipping_method ( $ flat_rate_id );
45
+ $ option_key = $ this -> shipping_method ->get_instance_option_key ();
46
+ $ options ['cost ' ] = '5 ' ;
33
47
update_option ( $ option_key , $ options );
34
48
}
35
49
36
50
/**
37
51
* Test should_show_express_checkout_button, tax logic.
38
52
*/
39
53
public function test_hides_ece_if_cannot_compute_taxes () {
54
+ $ this ->set_up_shipping_methods ();
55
+
40
56
$ wc_stripe_ece_helper_mock = $ this ->createPartialMock (
41
57
WC_Stripe_Express_Checkout_Helper::class,
42
58
[
@@ -98,6 +114,8 @@ public function test_hides_ece_if_cannot_compute_taxes() {
98
114
* Test should_show_express_checkout_button, gateway logic.
99
115
*/
100
116
public function test_hides_ece_if_stripe_gateway_unavailable () {
117
+ $ this ->set_up_shipping_methods ();
118
+
101
119
$ wc_stripe_ece_helper_mock = $ this ->createPartialMock (
102
120
WC_Stripe_Express_Checkout_Helper::class,
103
121
[
@@ -142,6 +160,8 @@ public function test_get_checkout_data() {
142
160
update_option ( 'woocommerce_currency ' , 'USD ' );
143
161
WC ()->cart ->empty_cart ();
144
162
163
+ $ this ->set_up_shipping_methods ();
164
+
145
165
$ wc_stripe_ece_helper = new WC_Stripe_Express_Checkout_Helper ();
146
166
$ checkout_data = $ wc_stripe_ece_helper ->get_checkout_data ();
147
167
@@ -154,4 +174,16 @@ public function test_get_checkout_data() {
154
174
$ this ->assertArrayHasKey ( 'displayName ' , $ checkout_data ['default_shipping_option ' ] );
155
175
$ this ->assertArrayHasKey ( 'amount ' , $ checkout_data ['default_shipping_option ' ] );
156
176
}
177
+
178
+ /**
179
+ * Test for get_checkout_data(), no shipping zones.
180
+ *
181
+ * This is in a separate test, to avoid problems with cached data.
182
+ */
183
+ public function test_get_checkout_data_no_shipping_zones () {
184
+ // When no shipping zones are set up, the default shipping option should be empty.
185
+ $ wc_stripe_ece_helper = new WC_Stripe_Express_Checkout_Helper ();
186
+ $ checkout_data = $ wc_stripe_ece_helper ->get_checkout_data ();
187
+ $ this ->assertEmpty ( $ checkout_data ['default_shipping_option ' ] );
188
+ }
157
189
}
0 commit comments