From 9915a508f36aebd21a8d5a024d9013cb77845eda Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Mon, 16 Dec 2024 22:07:11 +0200 Subject: [PATCH] fix all current unit tests --- .../License/Upgrade/displayUpgradePopin.php | 161 +++++++++++------- .../License/Upgrade/displayUpgradeSection.php | 11 ++ .../License/Upgrade/displayUpgradePopin.php | 2 +- .../License/Upgrade/displayUpgradeSection.php | 9 +- 4 files changed, 114 insertions(+), 69 deletions(-) diff --git a/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradePopin.php b/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradePopin.php index e379262c72..ef546ff82c 100644 --- a/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradePopin.php +++ b/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradePopin.php @@ -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/roger@wp-rocket.me/d89e18ee/plus/', - ], - 'infinite' => [ - 'name' => 'Infinite', - 'price' => 200, - 'websites' => 'Unlimited', - 'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/roger@wp-rocket.me/d89e18ee/infinite/', + 'growth' => [ + 'name' => 'Growth', + 'price' => 'x', + 'websites' => 'x', + 'upgrade_url' => 'x', ], ], ], @@ -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/roger@wp-rocket.me/d89e18ee/plus/', - 'saving' => 10, - 'regular_price' => 50, - ], - 'infinite' => [ - 'name' => 'Infinite', - 'price' => 160, - 'websites' => 'Unlimited', - 'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/roger@wp-rocket.me/d89e18ee/infinite/', - 'saving' => 40, - 'regular_price' => 200, + 'growth' => [ + 'name' => 'Growth', + 'price' => '40', + 'websites' => 'x', + 'upgrade_url' => 'x', + 'saving' => '10', + 'regular_price' => "50", ], ], ], @@ -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/roger@wp-rocket.me/d89e18ee/plus/', - ], - 'infinite' => [ - 'name' => 'Infinite', - 'price' => 200, - 'websites' => 'Unlimited', - 'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/roger@wp-rocket.me/d89e18ee/infinite/', + 'growth' => [ + 'name' => 'Growth', + 'price' => 'x', + 'websites' => 'x', + 'upgrade_url' => 'x', ], ], ], @@ -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/roger@wp-rocket.me/d89e18ee/plus/', - 'saving' => 10, - 'regular_price' => 50, - ], - 'infinite' => [ - 'name' => 'Infinite', - 'price' => 160, - 'websites' => 'Unlimited', - 'upgrade_url' => 'https://wp-rocket.me/checkout/upgrade/roger@wp-rocket.me/d89e18ee/infinite/', - 'saving' => 40, - 'regular_price' => 200, + 'growth' => [ + 'name' => 'Growth', + 'price' => '40', + 'websites' => 'x', + 'upgrade_url' => 'x', + 'saving' => '10', + 'regular_price' => "50", ], ], ], @@ -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/roger@wp-rocket.me/d89e18ee/infinite/', + 'growth' => [ + 'name' => 'Growth', + 'price' => 'x', + 'websites' => 'x', + 'upgrade_url' => 'x', ], ], ], @@ -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/roger@wp-rocket.me/d89e18ee/infinite/', - 'saving' => 30, - 'regular_price' => 150, + 'growth' => [ + 'name' => 'Growth', + 'price' => '40', + 'websites' => 'x', + 'upgrade_url' => 'x', + 'saving' => '10', + 'regular_price' => "50", ], ], ], diff --git a/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradeSection.php b/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradeSection.php index c17f0d3d8f..8d491969b7 100644 --- a/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradeSection.php +++ b/tests/Fixtures/inc/Engine/License/Upgrade/displayUpgradeSection.php @@ -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' => '', ], diff --git a/tests/Unit/inc/Engine/License/Upgrade/displayUpgradePopin.php b/tests/Unit/inc/Engine/License/Upgrade/displayUpgradePopin.php index 135d6f4f35..25009c3e82 100644 --- a/tests/Unit/inc/Engine/License/Upgrade/displayUpgradePopin.php +++ b/tests/Unit/inc/Engine/License/Upgrade/displayUpgradePopin.php @@ -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 ) ) { diff --git a/tests/Unit/inc/Engine/License/Upgrade/displayUpgradeSection.php b/tests/Unit/inc/Engine/License/Upgrade/displayUpgradeSection.php index 63cf4de554..969d903944 100644 --- a/tests/Unit/inc/Engine/License/Upgrade/displayUpgradeSection.php +++ b/tests/Unit/inc/Engine/License/Upgrade/displayUpgradeSection.php @@ -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()