From e0dad77e490eefb914408e53a91919ea5f4c0061 Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Mon, 29 Mar 2021 11:21:36 +0200 Subject: [PATCH 1/2] Fix logic for including the "payments" task in onboarding wizard The logic should be "if woo payments is installed and the country is US then remove the payments task" but the check was mistakenly being set to "or" so the task was removed whenever the country was US. --- includes/admin/class-wc-admin-dashboard-setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-dashboard-setup.php b/includes/admin/class-wc-admin-dashboard-setup.php index 8fdbc1e94de..0fb9f7cda83 100644 --- a/includes/admin/class-wc-admin-dashboard-setup.php +++ b/includes/admin/class-wc-admin-dashboard-setup.php @@ -178,7 +178,7 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) : } // payments can't be used when woocommerce-payments exists and country is US. - if ( $is_woo_payment_installed || 'US' === $country ) { + if ( $is_woo_payment_installed && 'US' === $country ) { unset( $this->tasks['payments'] ); } From ccb8cbddac0ce906c55e3e41e0f516b20ac98d0f Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Mon, 29 Mar 2021 17:04:54 +0200 Subject: [PATCH 2/2] Adjust tests for WC_Admin_Dashboard_Setup (consider 'payments' task) --- .../class-wc-admin-dashboard-setup-test.php | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php b/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php index 82ebf87cc05..83b678a86b9 100644 --- a/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php +++ b/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php @@ -14,12 +14,22 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case { * Set up */ public function setUp() { - // set default country to US so that 'payments' task does not get added. - // we want to remove payment tasks as they depend on installation & activation. - update_option( 'woocommerce_default_country', 'US' ); + // Set default country to non-US so that 'payments' task gets added but 'woocommerce-payments' doesn't, + // by default it won't be considered completed but we can manually change that as needed. + update_option( 'woocommerce_default_country', 'JP' ); + parent::setUp(); } + /** + * Tear down + */ + public function tearDown() { + remove_all_filters( 'woocommerce_available_payment_gateways' ); + + parent::tearDown(); + } + /** * Includes widget class and return the class. * @@ -75,13 +85,21 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case { } /** - * Tests the widget output when 0 task has been completed. + * Tests the widget output when 1 task has been completed. */ public function test_initial_widget_output() { + // Force the "payments" task to be considered incomplete. + add_filter( + 'woocommerce_available_payment_gateways', + function() { + return array(); + } + ); + $html = $this->get_widget_output(); $required_strings = array( - 'Step 0 of 5', + 'Step 0 of 6', 'You're almost there! Once you complete store setup you can start receiving orders.', 'Start selling', 'admin.php\?page=wc-admin&path=%2Fsetup-wizard', @@ -96,9 +114,22 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case { * Tests completed task count as it completes one by one */ public function test_widget_renders_completed_task_count() { - $completed_tasks = array(); + // Force the "payments" task to be considered completed + // by faking a valid payment gateway. + add_filter( + 'woocommerce_available_payment_gateways', + function() { + return array( + new class() extends WC_Payment_Gateway { + }, + ); + } + ); + + $completed_tasks = array( 'payments' ); $tasks = $this->get_widget()->get_tasks(); $tasks_count = count( $tasks ); + unset( $tasks['payments'] ); // That one is completed already. foreach ( $tasks as $key => $task ) { array_push( $completed_tasks, $key ); update_option( 'woocommerce_task_list_tracked_completed_tasks', $completed_tasks ); @@ -108,7 +139,7 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case { if ( $completed_tasks_count === $tasks_count ) { $this->assertEmpty( $this->get_widget_output() ); } else { - $this->assertRegexp( "/Step ${completed_tasks_count} of 5/", $this->get_widget_output() ); + $this->assertRegexp( "/Step ${completed_tasks_count} of 6/", $this->get_widget_output() ); } } } @@ -122,13 +153,13 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case { array( array( 'woocommerce_task_list_complete' => 'yes', - 'woocommerce_task_list_hidden' => 'no', + 'woocommerce_task_list_hidden' => 'no', ), ), array( array( 'woocommerce_task_list_complete' => 'no', - 'woocommerce_task_list_hidden' => 'yes', + 'woocommerce_task_list_hidden' => 'yes', ), ), );