Commit 77490abfa4f for woocommerce
commit 77490abfa4f5dc63761f3ca8009b40ed308fbc8e
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Tue Aug 4 13:54:15 2026 +0300
[tests] [Payments NOX] Add test coverage for Square's offline-preferred tagging (#67361)
* test: cover Square's preferred-offline tagging based on the onboarding profile
with_store_state_details() tags the Square suggestion as preferred
(and preferred for offline) when is_merchant_selling_offline() reports
the merchant self-identified as selling offline via the core
profiler, but no test exercised that behavior: the only test touching
these onboarding-profile answers (selling-offline suggestion counts)
only asserts on suggestion counts, and tagging a suggestion doesn't
change how many are returned.
Verified this gap concretely: mutation testing on
PaymentsExtensionSuggestions.php (via the static-code-verification
overlay's infection run) flagged an escaped mutant negating the
'no_im_selling_offline' / 'im_selling_both_online_and_offline' OR
condition in is_merchant_selling_offline() at line 4558-4559 -- no
existing test caught it.
Add test_get_country_extensions_square_offline_preferred_tags,
asserting Square's tags for both offline-selling answers (expect the
preferred tags), the online-only answer, the not-already-selling
business choice, and a skipped profiler (expect no preferred tags in
each). Confirmed this test fails under the exact escaped mutation and
passes against the current code.
No production code changed, so the changelog entry carries a Comment
only.
* test: Cover missing selling_online_answer branch and add AAA comments
is_merchant_selling_offline() has four falsy exit paths; the existing
data provider only exercised three. The unset-selling_online_answer
case (merchant answered "I'm already selling" but stopped before the
online/offline question) trips the inner isset() guard rather than a
value mismatch, and was left unverified. Also adds Arrange/Act/Assert
comments to the new test, matching its nearest sibling test above it.
Refs review feedback on PR #67361.
diff --git a/plugins/woocommerce/changelog/add-square-offline-preferred-tag-test b/plugins/woocommerce/changelog/add-square-offline-preferred-tag-test
new file mode 100644
index 00000000000..adc06f462cb
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-square-offline-preferred-tag-test
@@ -0,0 +1,5 @@
+Significance: patch
+Type: dev
+Comment: Only PHPUnit tests changes.
+
+
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
index 284cbb28d82..ba4447122db 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
@@ -89,7 +89,8 @@ class PaymentsExtensionSuggestionsTest extends WC_Unit_Test_Case {
// Arrange.
update_option(
OnboardingProfile::DATA_OPTION,
- array() // No data.
+ array()
+ // No data.
);
// Act.
@@ -104,7 +105,8 @@ class PaymentsExtensionSuggestionsTest extends WC_Unit_Test_Case {
OnboardingProfile::DATA_OPTION,
array(
'business_choice' => 'im_already_selling',
- 'selling_online_answer' => '', // No answer.
+ 'selling_online_answer' => '',
+ // No answer.
)
);
@@ -429,6 +431,88 @@ class PaymentsExtensionSuggestionsTest extends WC_Unit_Test_Case {
delete_option( OnboardingProfile::DATA_OPTION );
}
+ /**
+ * @testdox Should tag Square as preferred (and preferred for offline) only when the merchant self-identified as selling offline.
+ *
+ * @dataProvider data_provider_square_offline_preferred_tags
+ *
+ * @param array|null $onboarding_profile The onboarding profile option value. Null to simulate a skipped profiler.
+ * @param bool $expect_offline_preferred Whether Square is expected to carry the preferred (offline) tags.
+ */
+ public function test_get_country_extensions_square_offline_preferred_tags( ?array $onboarding_profile, bool $expect_offline_preferred ) {
+ // Arrange.
+ if ( null === $onboarding_profile ) {
+ delete_option( OnboardingProfile::DATA_OPTION );
+ } else {
+ update_option( OnboardingProfile::DATA_OPTION, $onboarding_profile );
+ }
+
+ // Act.
+ $extensions = $this->sut->get_country_extensions( 'US' );
+ $square_index = array_search( PaymentsExtensionSuggestions::SQUARE, array_column( $extensions, 'id' ), true );
+ $this->assertNotFalse( $square_index, 'Square should be in the US suggestions.' );
+ $square = $extensions[ $square_index ];
+
+ // Assert.
+ if ( $expect_offline_preferred ) {
+ $this->assertContains( PaymentsExtensionSuggestions::TAG_PREFERRED, $square['tags'] );
+ $this->assertContains( PaymentsExtensionSuggestions::TAG_PREFERRED_OFFLINE, $square['tags'] );
+ } else {
+ $this->assertNotContains( PaymentsExtensionSuggestions::TAG_PREFERRED, $square['tags'] );
+ $this->assertNotContains( PaymentsExtensionSuggestions::TAG_PREFERRED_OFFLINE, $square['tags'] );
+ }
+
+ delete_option( OnboardingProfile::DATA_OPTION );
+ }
+
+ /**
+ * Data provider for test_get_country_extensions_square_offline_preferred_tags.
+ *
+ * @return array
+ */
+ public function data_provider_square_offline_preferred_tags(): array {
+ return array(
+ 'selling offline only' => array(
+ array(
+ 'business_choice' => 'im_already_selling',
+ 'selling_online_answer' => 'no_im_selling_offline',
+ ),
+ true,
+ ),
+ 'selling both online and offline' => array(
+ array(
+ 'business_choice' => 'im_already_selling',
+ 'selling_online_answer' => 'im_selling_both_online_and_offline',
+ ),
+ true,
+ ),
+ 'selling online only' => array(
+ array(
+ 'business_choice' => 'im_already_selling',
+ 'selling_online_answer' => 'yes_im_selling_online',
+ ),
+ false,
+ ),
+ 'not already selling' => array(
+ array(
+ 'business_choice' => 'im_just_starting_my_business',
+ 'selling_online_answer' => 'no_im_selling_offline',
+ ),
+ false,
+ ),
+ 'already selling, no online answer' => array(
+ array(
+ 'business_choice' => 'im_already_selling',
+ ),
+ false,
+ ),
+ 'profiler skipped' => array(
+ null,
+ false,
+ ),
+ );
+ }
+
/**
* Data provider for test_get_country_extensions_count_with_merchant_selling_offline.
*