Skip to content

Commit

Permalink
Multi tiers Update banner copy - part 3 (PR #7196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal authored Dec 19, 2024
1 parent 5ac0171 commit 12cea3d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
39 changes: 20 additions & 19 deletions inc/Engine/License/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 = <br>, %3$s = <strong>, %4$s = promotion discount percentage, %5$s = </strong>.
_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 = <br>, %3$s = <strong>, %4$s = promotion discount percentage, %5$s = </strong>, %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,
'<br>',
'<strong>',
$promo_discount . '%',
'</strong>'
'</strong>',
implode( ', ', $license_types ),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
],
],
Expand Down Expand Up @@ -162,7 +168,7 @@
get a<strong>
20% off</strong>
for<strong>
upgrading your license to Plus or Infinite!</strong>
upgrading your license to Growth!</strong>
</p>
</div>
<div class="rocket-promo-cta-block">
Expand Down Expand Up @@ -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,
]
],
],
Expand Down Expand Up @@ -254,7 +266,7 @@
get a<strong>
20% off</strong>
for<strong>
upgrading your license to Infinite!</strong>
upgrading your license to Multi!</strong>
</p>
</div>
<div class="rocket-promo-cta-block">
Expand Down
36 changes: 27 additions & 9 deletions tests/Fixtures/inc/Engine/License/Upgrade/displayPromoBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Plus or Infinite!</strong>',
'message' => 'Take advantage of Halloween to speed up more websites:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Growth!</strong>',
],
],
'testShouldReturnDataWhenPromoNotSeenAndLicenseBetweenSingleAndPlus' => [
Expand All @@ -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:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Plus or Infinite!</strong>',
'message' => 'Take advantage of Halloween to speed up more websites:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Multi!</strong>',
],
],
'testShouldReturnDataWhenPromoNotSeenAndLicenseIsPlus' => [
Expand All @@ -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:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Infinite!</strong>',
'message' => 'Take advantage of Halloween to speed up more websites:<br> get a <strong>20% off</strong> for <strong>upgrading your license to Growth!</strong>',
],
],
];
6 changes: 3 additions & 3 deletions tests/Unit/inc/Engine/License/Upgrade/displayPromoBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand All @@ -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 );
Expand All @@ -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' )
Expand Down

0 comments on commit 12cea3d

Please sign in to comment.