diff --git a/inc/Engine/License/Upgrade.php b/inc/Engine/License/Upgrade.php index 1b198c2d38..70608e4b3a 100644 --- a/inc/Engine/License/Upgrade.php +++ b/inc/Engine/License/Upgrade.php @@ -219,6 +219,20 @@ private function get_countdown_data() { return $data; } + /** + * Get upgrade types + * + * @return array + */ + private function get_upgrade_types(): array { + $types = []; + foreach ( $this->get_upgrade_choices() as $choice_key => $choice ) { + $types[] = 'stacked' === $choice_key ? $choice[0]['name'] : $choice['name']; + } + + return $types; + } + /** * Returns the promotion message to display in the banner * @@ -228,33 +242,20 @@ private function get_countdown_data() { * @return string */ private function get_promo_message( $promo_name = '', $promo_discount = 0 ) { - $choices = 0; - $license = $this->user->get_license_type(); - $plus_websites = $this->pricing->get_plus_websites_count(); - - if ( $license === $plus_websites ) { - $choices = 2; - } elseif ( - $license >= $this->pricing->get_single_websites_count() - && - $license < $plus_websites - ) { - $choices = 1; - } + $license_types = $this->get_upgrade_types(); return sprintf( - // translators: %1$s = promotion name, %2$s =
, %3$s = , %4$s = promotion discount percentage, %5$s = . - _n( - 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Plus or Infinite!%5$s', - 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Infinite!%5$s', - $choices, + // translators: %1$s = promotion name, %2$s =
, %3$s = , %4$s = promotion discount percentage, %5$s = , %6$s = Growth/Multi. + esc_html__( + 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to %6$s!%5$s', 'rocket' ), $promo_name, '
', '', $promo_discount . '%', - '' + '', + implode( ', ', $license_types ), ); } diff --git a/tests/Fixtures/inc/Engine/License/Subscriber/displayPromoBanner.php b/tests/Fixtures/inc/Engine/License/Subscriber/displayPromoBanner.php index aa05f5d91e..d2ace3a3f6 100644 --- a/tests/Fixtures/inc/Engine/License/Subscriber/displayPromoBanner.php +++ b/tests/Fixtures/inc/Engine/License/Subscriber/displayPromoBanner.php @@ -113,7 +113,13 @@ 'prices' => [ 'upgrades' => [ (object) [ - "name"=> "Growth", + 'name' => 'Growth', + 'type' => 'growth', + 'saving' => 150, + 'upgrade_url' => "https://growthupgradeurl.com/", + 'regular_price' => 200, + 'websites' => "3", + 'stacked' => false, ] ], ], @@ -162,7 +168,7 @@ get a 20% off for - upgrading your license to Plus or Infinite! + upgrading your license to Growth!

@@ -205,7 +211,13 @@ 'prices' => [ 'upgrades' => [ (object) [ - "name"=> "Growth", + 'name' => 'Multi', + 'type' => 'multi100', + 'saving' => 150, + 'upgrade_url' => "https://growthupgradeurl.com/", + 'regular_price' => 200, + 'websites' => "3", + 'stacked' => false, ] ], ], @@ -254,7 +266,7 @@ get a 20% off for - upgrading your license to Infinite! + upgrading your license to Multi!

diff --git a/tests/Fixtures/inc/Engine/License/Upgrade/displayPromoBanner.php b/tests/Fixtures/inc/Engine/License/Upgrade/displayPromoBanner.php index 9a84c005f5..b8a19ca335 100644 --- a/tests/Fixtures/inc/Engine/License/Upgrade/displayPromoBanner.php +++ b/tests/Fixtures/inc/Engine/License/Upgrade/displayPromoBanner.php @@ -95,17 +95,23 @@ 'websites' => 3, ], ], - 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Plus or Infinite!%5$s', + 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to %6$s!%5$s', 'upgrades' => [ (object) [ - "name"=> "Growth", + 'name' => 'Growth', + 'type' => 'growth', + 'saving' => 150, + 'upgrade_url' => "https://growthupgradeurl.com/", + 'regular_price' => 200, + 'websites' => "3", + 'stacked' => false, ] ], ], 'expected' => [ 'name' => 'Halloween', 'discount_percent' => 20, - 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Plus or Infinite!', + 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Growth!', ], ], 'testShouldReturnDataWhenPromoNotSeenAndLicenseBetweenSingleAndPlus' => [ @@ -129,17 +135,23 @@ 'websites' => 3, ], ], - 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Plus or Infinite!%5$s', + 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to %6$s!%5$s', 'upgrades' => [ (object) [ - "name"=> "Multi", + 'name' => 'Multi', + 'type' => 'multi100', + 'saving' => 100, + 'upgrade_url' => "https://growthupgradeurl.com/", + 'regular_price' => 150, + 'websites' => "3", + 'stacked' => false, ] ], ], 'expected' => [ 'name' => 'Halloween', 'discount_percent' => 20, - 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Plus or Infinite!', + 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Multi!', ], ], 'testShouldReturnDataWhenPromoNotSeenAndLicenseIsPlus' => [ @@ -163,17 +175,23 @@ 'websites' => 3, ], ], - 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Infinite!%5$s', + 'message' => 'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to %6$s!%5$s', 'upgrades' => [ (object) [ - "name"=> "Growth", + 'name' => 'Growth', + 'type' => 'growth', + 'saving' => 200, + 'upgrade_url' => "https://growthupgradeurl.com/", + 'regular_price' => 250, + 'websites' => "3", + 'stacked' => false, ] ], ], 'expected' => [ 'name' => 'Halloween', 'discount_percent' => 20, - 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Infinite!', + 'message' => 'Take advantage of Halloween to speed up more websites:
get a 20% off for upgrading your license to Growth!', ], ], ]; diff --git a/tests/Unit/inc/Engine/License/Upgrade/displayPromoBanner.php b/tests/Unit/inc/Engine/License/Upgrade/displayPromoBanner.php index 032eb9cbe2..de19371336 100644 --- a/tests/Unit/inc/Engine/License/Upgrade/displayPromoBanner.php +++ b/tests/Unit/inc/Engine/License/Upgrade/displayPromoBanner.php @@ -50,7 +50,7 @@ public function testShouldReturnExpected( $config, $expected ) { $this->user->shouldReceive( 'get_available_upgrades' ) ->atMost() - ->once() + ->twice() ->andReturn( $config['upgrades'] ?? [] ); $this->user->shouldReceive( 'get_license_expiration' ) @@ -65,7 +65,7 @@ public function testShouldReturnExpected( $config, $expected ) { $this->pricing->shouldReceive( 'is_promo_active' ) ->atMost() - ->once() + ->twice() ->andReturn( $config['promo_active'] ); Functions\when( 'get_current_user_id' )->justReturn( 1 ); @@ -91,7 +91,7 @@ public function testShouldReturnExpected( $config, $expected ) { ->twice() ->andReturn( $config['pricing']['plus']['websites'] ); - Functions\when( '_n' ) + Functions\when( 'esc_html__' ) ->justReturn( $config['message'] ); $this->pricing->shouldReceive( 'get_promo_end' )