8
8
/**
9
9
* WC_Stripe_Apple_Pay_Registration unit tests.
10
10
*/
11
- class WC_Stripe_Apple_Pay_Registration_Test extends WP_UnitTestCase {
11
+ class WC_Stripe_Apple_Pay_Registration_Test extends WC_Mock_Stripe_API_Unit_Test_Case {
12
12
13
13
/**
14
14
* System under test.
@@ -38,6 +38,13 @@ class WC_Stripe_Apple_Pay_Registration_Test extends WP_UnitTestCase {
38
38
*/
39
39
private $ file_contents ;
40
40
41
+ /**
42
+ * UPE test helper.
43
+ *
44
+ * @var UPE_Test_Helper
45
+ */
46
+ private $ upe_helper ;
47
+
41
48
/**
42
49
* Pre-test setup
43
50
*/
@@ -57,6 +64,44 @@ public function set_up() {
57
64
58
65
$ this ->file_name = 'apple-developer-merchantid-domain-association ' ;
59
66
$ this ->initial_file_contents = file_get_contents ( WC_STRIPE_PLUGIN_PATH . '/ ' . $ this ->file_name ); // @codingStandardsIgnoreLine
67
+
68
+ $ this ->mock_wc_apple_pay_registration ->stripe_settings = [
69
+ 'enabled ' => 'yes ' ,
70
+ 'secret_key ' => '123 ' ,
71
+ ];
72
+
73
+ $ this ->upe_helper = new UPE_Test_Helper ();
74
+ }
75
+
76
+ /**
77
+ * Disable UPE and enable/disable Apple Pay/Google Pay.
78
+ *
79
+ * @param bool $payment_request_enabled Whether Apple Pay/Google Pay should be enabled.
80
+ */
81
+ private function legacy_checkout_setup ( $ payment_request_enabled = true ) {
82
+ $ this ->upe_helper ->disable_upe ();
83
+ $ this ->upe_helper ->reload_payment_gateways ();
84
+
85
+ $ settings = WC_Stripe_Helper::get_stripe_settings ();
86
+ $ settings ['payment_request ' ] = $ payment_request_enabled ? 'yes ' : 'no ' ;
87
+ WC_Stripe_Helper::update_main_stripe_settings ( $ settings );
88
+ WC_Stripe::get_instance ()->get_main_stripe_gateway ()->init_settings ();
89
+ }
90
+
91
+ /**
92
+ * Enable UPE and enable/disable Apple Pay/Google Pay.
93
+ *
94
+ * @param bool $payment_request_enabled Whether Apple Pay/Google Pay should be enabled.
95
+ */
96
+ private function upe_checkout_setup ( $ payment_request_enabled = true ) {
97
+ $ this ->upe_helper ->enable_upe ();
98
+ $ this ->upe_helper ->reload_payment_gateways ();
99
+
100
+ if ( $ payment_request_enabled ) {
101
+ $ this ->mock_payment_method_configurations ( [ WC_Stripe_Payment_Methods::APPLE_PAY ] );
102
+ } else {
103
+ $ this ->mock_payment_method_configurations ( [ WC_Stripe_Payment_Methods::CARD , WC_Stripe_Payment_Methods::LINK ] );
104
+ }
60
105
}
61
106
62
107
public function tear_down () {
@@ -92,6 +137,8 @@ public function test_add_domain_association_rewrite_rule() {
92
137
}
93
138
94
139
public function test_verify_domain_if_configured_no_secret_key () {
140
+ $ this ->legacy_checkout_setup ();
141
+
95
142
WC_Stripe::get_instance ()->account = $ this ->getMockBuilder ( 'WC_Stripe_Account ' )
96
143
->disableOriginalConstructor ()
97
144
->setMethods (
@@ -105,14 +152,14 @@ public function test_verify_domain_if_configured_no_secret_key() {
105
152
->expects ( $ this ->never () )
106
153
->method ( 'get_cached_account_data ' );
107
154
108
- $ this ->mock_wc_apple_pay_registration ->stripe_settings = [
109
- 'enabled ' => 'yes ' ,
110
- 'secret_key ' => '' ,
111
- ];
155
+ $ this ->mock_wc_apple_pay_registration ->stripe_settings ['secret_key ' ] = '' ;
156
+
112
157
$ this ->mock_wc_apple_pay_registration ->verify_domain_if_configured ();
113
158
}
114
159
115
160
public function test_verify_domain_if_configured_supported_country () {
161
+ $ this ->legacy_checkout_setup ();
162
+
116
163
WC_Stripe::get_instance ()->account = $ this ->getMockBuilder ( 'WC_Stripe_Account ' )
117
164
->disableOriginalConstructor ()
118
165
->setMethods (
@@ -131,15 +178,12 @@ public function test_verify_domain_if_configured_supported_country() {
131
178
->expects ( $ this ->once () )
132
179
->method ( 'update_domain_association_file ' );
133
180
134
- $ this ->mock_wc_apple_pay_registration ->stripe_settings = [
135
- 'enabled ' => 'yes ' ,
136
- 'payment_request ' => 'yes ' ,
137
- 'secret_key ' => '123 ' ,
138
- ];
139
181
$ this ->mock_wc_apple_pay_registration ->verify_domain_if_configured ();
140
182
}
141
183
142
184
public function test_verify_domain_if_configured_unsupported_country () {
185
+ $ this ->legacy_checkout_setup ();
186
+
143
187
WC_Stripe::get_instance ()->account = $ this ->getMockBuilder ( 'WC_Stripe_Account ' )
144
188
->disableOriginalConstructor ()
145
189
->setMethods (
@@ -158,11 +202,49 @@ public function test_verify_domain_if_configured_unsupported_country() {
158
202
->expects ( $ this ->never () )
159
203
->method ( 'update_domain_association_file ' );
160
204
161
- $ this ->mock_wc_apple_pay_registration ->stripe_settings = [
162
- 'enabled ' => 'yes ' ,
163
- 'payment_request ' => 'yes ' ,
164
- 'secret_key ' => '123 ' ,
165
- ];
166
205
$ this ->mock_wc_apple_pay_registration ->verify_domain_if_configured ();
167
206
}
207
+
208
+ /**
209
+ * Test for when Apple Pay (legacy PRB) are disabled.
210
+ */
211
+ public function test_verify_domain_if_configured_apple_pay_disabled () {
212
+ $ this ->legacy_checkout_setup ( false );
213
+
214
+ $ this ->mock_wc_apple_pay_registration
215
+ ->expects ( $ this ->never () )
216
+ ->method ( 'update_domain_association_file ' );
217
+
218
+ $ this ->mock_wc_apple_pay_registration ->verify_domain_if_configured ();
219
+ }
220
+
221
+ /**
222
+ * Test for UPE, Apple Pay enabled.
223
+ */
224
+ public function test_verify_domain_if_configured_upe_apple_pay_enabled () {
225
+ $ this ->upe_checkout_setup ();
226
+
227
+ $ this ->mock_wc_apple_pay_registration
228
+ ->expects ( $ this ->once () )
229
+ ->method ( 'update_domain_association_file ' );
230
+
231
+ $ this ->mock_wc_apple_pay_registration ->verify_domain_if_configured ();
232
+ }
233
+
234
+ /**
235
+ * Test for UPE, Apple Pay disabled.
236
+ */
237
+ public function test_verify_domain_if_configured_upe_apple_pay_disabled () {
238
+ $ this ->upe_checkout_setup ( false );
239
+
240
+ $ this ->mock_payment_method_configurations ( [ WC_Stripe_Payment_Methods::CARD ] );
241
+
242
+ $ this ->mock_wc_apple_pay_registration
243
+ ->expects ( $ this ->never () )
244
+ ->method ( 'update_domain_association_file ' );
245
+
246
+ // Restore initial setting for UPE.
247
+ $ this ->upe_helper ->disable_upe ();
248
+ $ this ->upe_helper ->reload_payment_gateways ();
249
+ }
168
250
}
0 commit comments