Skip to content

Commit 16f8862

Browse files
authored
Add Feature Flag for Development of Progressive Onboarding (#5499)
* Adding changelog entry. * Added the feature flag, and updated the unit tests. * Update to use a constant to be more easily refactorable in future.
1 parent 23e481f commit 16f8862

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

changelog/dev-5486-po-feature-flag

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: dev
3+
4+
Adding a feature flag to allow further development of onboarding UX - currently this will have no effect on live stores.

includes/class-wc-payments-features.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class WC_Payments_Features {
1717
const WCPAY_SUBSCRIPTIONS_FLAG_NAME = '_wcpay_feature_subscriptions';
1818
const WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_express_checkout';
1919
const AUTH_AND_CAPTURE_FLAG_NAME = '_wcpay_feature_auth_and_capture';
20+
const PROGRESSIVE_ONBOARDING_FLAG_NAME = '_wcpay_feature_progressive_onboarding';
2021

2122
/**
2223
* Checks whether the UPE gateway is enabled
@@ -164,6 +165,15 @@ public static function is_auth_and_capture_enabled() {
164165
return '1' === get_option( self::AUTH_AND_CAPTURE_FLAG_NAME, '1' );
165166
}
166167

168+
/**
169+
* Checks whether Progressive Onboarding is enabled.
170+
*
171+
* @return bool
172+
*/
173+
public static function is_progressive_onboarding_enabled(): bool {
174+
return '1' === get_option( self::PROGRESSIVE_ONBOARDING_FLAG_NAME, '0' );
175+
}
176+
167177
/**
168178
* Returns feature flags as an array suitable for display on the front-end.
169179
*
@@ -182,6 +192,7 @@ public static function to_array() {
182192
'clientSecretEncryption' => self::is_client_secret_encryption_enabled(),
183193
'woopayExpressCheckout' => self::is_woopay_express_checkout_enabled(),
184194
'isAuthAndCaptureEnabled' => self::is_auth_and_capture_enabled(),
195+
'progressiveOnboarding' => self::is_progressive_onboarding_enabled(),
185196
]
186197
);
187198
}

tests/unit/test-class-wc-payments-features.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
* @package WooCommerce\Payments\Tests
66
*/
77

8+
use PHPUnit\Framework\MockObject\MockObject;
9+
use WCPay\Database_Cache;
10+
811
/**
912
* WC_Payments_Features unit tests.
1013
*/
1114
class WC_Payments_Features_Test extends WCPAY_UnitTestCase {
1215

16+
/**
17+
* @var Database_Cache|MockObject
18+
*/
19+
protected $mock_cache;
20+
1321
const FLAG_OPTION_NAME_TO_FRONTEND_KEY_MAPPING = [
1422
'_wcpay_feature_upe' => 'upe',
1523
'_wcpay_feature_upe_settings_preview' => 'upeSettingsPreview',
@@ -18,6 +26,7 @@ class WC_Payments_Features_Test extends WCPAY_UnitTestCase {
1826
'_wcpay_feature_account_overview_task_list' => 'accountOverviewTaskList',
1927
'_wcpay_feature_custom_deposit_schedules' => 'customDepositSchedules',
2028
'_wcpay_feature_auth_and_capture' => 'isAuthAndCaptureEnabled',
29+
'_wcpay_feature_progressive_onboarding' => 'progressiveOnboarding',
2130
];
2231

2332
public function set_up() {
@@ -149,7 +158,7 @@ function ( $pre_option, $option, $default ) {
149158

150159
public function test_is_woopay_express_checkout_enabled_returns_false_when_platform_checkout_eligible_is_false() {
151160
add_filter(
152-
'pre_option__wcpay_feature_woopay_express_checkout',
161+
'pre_option__' . WC_Payments_Features::PROGRESSIVE_ONBOARDING_FLAG_NAME,
153162
function ( $pre_option, $option, $default ) {
154163
return '1';
155164
},
@@ -160,6 +169,35 @@ function ( $pre_option, $option, $default ) {
160169
$this->assertFalse( WC_Payments_Features::is_woopay_express_checkout_enabled() );
161170
}
162171

172+
public function test_is_progressive_onboarding_enabled_returns_true() {
173+
add_filter(
174+
'pre_option_' . WC_Payments_Features::PROGRESSIVE_ONBOARDING_FLAG_NAME,
175+
function ( $pre_option, $option, $default ) {
176+
return '1';
177+
},
178+
10,
179+
3
180+
);
181+
$this->assertTrue( WC_Payments_Features::is_progressive_onboarding_enabled() );
182+
}
183+
184+
public function test_is_progressive_onboarding_enabled_returns_false_when_flag_is_false() {
185+
add_filter(
186+
'pre_option_' . WC_Payments_Features::PROGRESSIVE_ONBOARDING_FLAG_NAME,
187+
function ( $pre_option, $option, $default ) {
188+
return '0';
189+
},
190+
10,
191+
3
192+
);
193+
$this->assertFalse( WC_Payments_Features::is_progressive_onboarding_enabled() );
194+
$this->assertArrayNotHasKey( 'progressiveOnboarding', WC_Payments_Features::to_array() );
195+
}
196+
197+
public function test_is_progressive_onboarding_enabled_returns_false_when_flag_is_not_set() {
198+
$this->assertFalse( WC_Payments_Features::is_progressive_onboarding_enabled() );
199+
}
200+
163201
private function setup_enabled_flags( array $enabled_flags ) {
164202
foreach ( array_keys( self::FLAG_OPTION_NAME_TO_FRONTEND_KEY_MAPPING ) as $flag ) {
165203
add_filter(

0 commit comments

Comments
 (0)