Skip to content

Commit

Permalink
fix all current unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Dec 16, 2024
1 parent 805425b commit 9915a50
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 69 deletions.
161 changes: 97 additions & 64 deletions tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradePopin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "x",
'upgrade_url' => "x",
'regular_price' => "x",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => false,
'upgrades' => [
'plus' => [
'name' => 'Plus',
'price' => 50,
'websites' => 3,
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/plus/',
],
'infinite' => [
'name' => 'Infinite',
'price' => 200,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'growth' => [
'name' => 'Growth',
'price' => 'x',
'websites' => 'x',
'upgrade_url' => 'x',
],
],
],
Expand All @@ -88,25 +88,28 @@
],
],
'promo_active' => true,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "40",
'upgrade_url' => "x",
'regular_price' => "50",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => true,
'upgrades' => [
'plus' => [
'name' => 'Plus',
'price' => 40,
'websites' => 3,
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/plus/',
'saving' => 10,
'regular_price' => 50,
],
'infinite' => [
'name' => 'Infinite',
'price' => 160,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'saving' => 40,
'regular_price' => 200,
'growth' => [
'name' => 'Growth',
'price' => '40',
'websites' => 'x',
'upgrade_url' => 'x',
'saving' => '10',
'regular_price' => "50",
],
],
],
Expand All @@ -133,21 +136,26 @@
],
],
'promo_active' => false,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "x",
'upgrade_url' => "x",
'regular_price' => "x",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => false,
'upgrades' => [
'plus' => [
'name' => 'Plus',
'price' => 50,
'websites' => 3,
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/plus/',
],
'infinite' => [
'name' => 'Infinite',
'price' => 200,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'growth' => [
'name' => 'Growth',
'price' => 'x',
'websites' => 'x',
'upgrade_url' => 'x',
],
],
],
Expand All @@ -174,25 +182,28 @@
],
],
'promo_active' => true,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "40",
'upgrade_url' => "x",
'regular_price' => "50",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => true,
'upgrades' => [
'plus' => [
'name' => 'Plus',
'price' => 40,
'websites' => 3,
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/plus/',
'saving' => 10,
'regular_price' => 50,
],
'infinite' => [
'name' => 'Infinite',
'price' => 160,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'saving' => 40,
'regular_price' => 200,
'growth' => [
'name' => 'Growth',
'price' => '40',
'websites' => 'x',
'upgrade_url' => 'x',
'saving' => '10',
'regular_price' => "50",
],
],
],
Expand All @@ -219,15 +230,26 @@
],
],
'promo_active' => false,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "x",
'upgrade_url' => "x",
'regular_price' => "x",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => false,
'upgrades' => [
'infinite' => [
'name' => 'Infinite',
'price' => 150,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'growth' => [
'name' => 'Growth',
'price' => 'x',
'websites' => 'x',
'upgrade_url' => 'x',
],
],
],
Expand All @@ -254,17 +276,28 @@
],
],
'promo_active' => true,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "40",
'upgrade_url' => "x",
'regular_price' => "50",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => [
'is_promo_active' => true,
'upgrades' => [
'infinite' => [
'name' => 'Infinite',
'price' => 120,
'websites' => 'Unlimited',
'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/[email protected]/d89e18ee/infinite/',
'saving' => 30,
'regular_price' => 150,
'growth' => [
'name' => 'Growth',
'price' => '40',
'websites' => 'x',
'upgrade_url' => 'x',
'saving' => '10',
'regular_price' => "50",
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
'config' => [
'license_account' => 1,
'licence_expiration' => false,
'upgrades' => [
(object) [
'name' => 'Growth',
'type' => 'growth',
'saving' => "40",
'upgrade_url' => "x",
'regular_price' => "50",
'websites' => "x",
'stacked' => false,
]
],
],
'expected' => '',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testShouldReturnExpected( $config, $expected ) {

$this->user->shouldReceive( 'get_available_upgrades' )
->atMost()
->once()
->twice()
->andReturn( $config['upgrades'] ?? [] );

if ( ! is_null( $expected ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ public function setUp() : void {
* @dataProvider configTestData
*/
public function testShouldReturnExpected( $config, $expected ) {
$this->user->shouldReceive( 'get_license_type' )
->once()
->andReturn( $config['license_account'] );

$this->user->shouldReceive( 'is_license_expired' )
->atMost()
->times( 1 )
->andReturn( $config['licence_expiration'] );

$this->user->shouldReceive( 'get_available_upgrades' )
->atMost()
->once()
->andReturn( $config['upgrades'] ?? [] );

if ( ! is_null( $expected ) ) {
$this->upgrade->shouldReceive( 'generate' )
->once()
Expand Down

0 comments on commit 9915a50

Please sign in to comment.