3
3
namespace WooCommerce \Stripe \Tests ;
4
4
5
5
use WC_Stripe_Feature_Flags ;
6
+ use WooCommerce \Stripe \Tests \Helpers \PMC_Test_Helper ;
6
7
use WP_UnitTestCase ;
7
8
8
9
/**
@@ -16,19 +17,33 @@ class WC_Stripe_Feature_Flags_Test extends WP_UnitTestCase {
16
17
/**
17
18
* Test for `is_oc_available`.
18
19
*
19
- * @param string $option_value The value of the feature flag option .
20
+ * @param bool $pmc_enabled Whether the Payment Method Configuration API is enabled .
20
21
* @param string $filter_function The filter function to apply.
21
22
* @param bool $expected The expected result.
22
23
* @return void
23
24
* @dataProvider provide_test_is_oc_available
24
25
*/
25
- public function test_is_oc_available ( $ option_value , $ filter_function , $ expected ) {
26
+ public function test_is_oc_available ( $ pmc_enabled , $ filter_function , $ expected ) {
27
+ // Mock the payment method configuration for the test, to avoid it being disabled by default.
28
+ PMC_Test_Helper::cache_mocked_configuration ();
29
+
30
+ if ( $ pmc_enabled ) {
31
+ PMC_Test_Helper::enable_pmc ();
32
+ } else {
33
+ PMC_Test_Helper::disable_pmc ();
34
+ }
35
+
26
36
if ( ! empty ( $ filter_function ) ) {
27
37
add_filter ( 'wc_stripe_is_optimized_checkout_available ' , $ filter_function );
28
38
}
29
39
30
- update_option ( WC_Stripe_Feature_Flags::OC_FEATURE_FLAG_NAME , $ option_value );
31
- $ this ->assertSame ( $ expected , WC_Stripe_Feature_Flags::is_oc_available () );
40
+ $ actual = WC_Stripe_Feature_Flags::is_oc_available ();
41
+
42
+ // Clean up
43
+ PMC_Test_Helper::disable_pmc ();
44
+ PMC_Test_Helper::delete_cached_configuration ();
45
+
46
+ $ this ->assertSame ( $ expected , $ actual );
32
47
33
48
if ( ! empty ( $ filter_function ) ) {
34
49
remove_filter ( 'wc_stripe_is_optimized_checkout_available ' , $ filter_function );
@@ -42,23 +57,28 @@ public function test_is_oc_available( $option_value, $filter_function, $expected
42
57
*/
43
58
public function provide_test_is_oc_available () {
44
59
return [
45
- 'available ' => [
46
- 'option value ' => ' yes ' ,
60
+ 'PMC enabled ' => [
61
+ 'PMC enabled ' => true ,
47
62
'filter function ' => '' ,
48
63
'expected ' => true ,
49
64
],
50
- 'not available ' => [
51
- 'option value ' => ' no ' ,
65
+ 'PMC disabled ' => [
66
+ 'PMC enabled ' => false ,
52
67
'filter function ' => '' ,
53
68
'expected ' => false ,
54
69
],
55
- 'filter set to true ' => [
56
- 'option value ' => 'no ' ,
70
+ 'PMC disabled, filter set to true (ignored) ' => [
71
+ 'PMC enabled ' => false ,
72
+ 'filter function ' => '__return_true ' ,
73
+ 'expected ' => false ,
74
+ ],
75
+ 'filter set to true ' => [
76
+ 'PMC enabled ' => true ,
57
77
'filter function ' => '__return_true ' ,
58
78
'expected ' => true ,
59
79
],
60
- 'filter set to false ' => [
61
- 'option value ' => ' yes ' ,
80
+ 'filter set to false ' => [
81
+ 'PMC enabled ' => true ,
62
82
'filter function ' => '__return_false ' ,
63
83
'expected ' => false ,
64
84
],
0 commit comments