diff --git a/mailpoet/lib/WPCOM/DotcomHelperFunctions.php b/mailpoet/lib/WPCOM/DotcomHelperFunctions.php index 4cd1e9937f..d030dba7fb 100644 --- a/mailpoet/lib/WPCOM/DotcomHelperFunctions.php +++ b/mailpoet/lib/WPCOM/DotcomHelperFunctions.php @@ -40,6 +40,10 @@ class DotcomHelperFunctions { return function_exists('wc_calypso_bridge_is_ecommerce_trial_plan') && wc_calypso_bridge_is_ecommerce_trial_plan(); } + public function isEcommerceWPCom(): bool { + return function_exists('wc_calypso_bridge_is_wpcom_ecommerce_plan') && wc_calypso_bridge_is_wpcom_ecommerce_plan(); + } + /** * Returns the plan name for the current site if hosted on WordPress.com. * Empty otherwise. @@ -47,20 +51,16 @@ class DotcomHelperFunctions { public function getDotcomPlan(): string { if ($this->isWooExpressPerformance()) { return 'performance'; - } - - if ($this->isWooExpressEssential()) { + } elseif ($this->isWooExpressEssential()) { return 'essential'; - } - - if ($this->isBusiness()) { + } elseif ($this->isBusiness()) { return 'business'; - } - - if ($this->isEcommerceTrial()) { + } elseif ($this->isEcommerceTrial()) { return 'ecommerce_trial'; + } elseif ($this->isEcommerceWPCom()) { + return 'ecommerce_wpcom'; + } else { + return ''; } - - return ''; } } diff --git a/mailpoet/tests/unit/WPCOM/DotcomHelperFunctionsTest.php b/mailpoet/tests/unit/WPCOM/DotcomHelperFunctionsTest.php index 04c94f04ce..c09b542cd2 100644 --- a/mailpoet/tests/unit/WPCOM/DotcomHelperFunctionsTest.php +++ b/mailpoet/tests/unit/WPCOM/DotcomHelperFunctionsTest.php @@ -48,4 +48,10 @@ class DotcomHelperFunctionsTest extends \MailPoetUnitTest { $dotcomHelper->method('isEcommerceTrial')->willReturn(true); expect($dotcomHelper->getDotcomPlan())->equals('ecommerce_trial'); } + + public function testItReturnsEcommerceWPComIfEcommerceWPCom() { + $dotcomHelper = $this->createPartialMock(DotcomHelperFunctions::class, ['isEcommerceWPCom']); + $dotcomHelper->method('isEcommerceWPCom')->willReturn(true); + expect($dotcomHelper->getDotcomPlan())->equals('ecommerce_wpcom'); + } }