-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/Fixtures/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
return [ | ||
'testShouldCallSendToSaas' => [ | ||
'config' => [ | ||
'wp_env' => 'production', | ||
'remove_unused_css' => 0, | ||
'factories' => [1], | ||
'license_expired' => false, | ||
'home_url' => 'http://example.com/', | ||
], | ||
'expected' => 1, | ||
], | ||
'testShouldNotCallSendToSaasWhenLicenseExpired' => [ | ||
'config' => [ | ||
'wp_env' => 'production', | ||
'remove_unused_css' => 0, | ||
'factories' => [1], | ||
'license_expired' => true, | ||
'home_url' => 'http://example.com/', | ||
], | ||
'expected' => 0, | ||
], | ||
'testShouldNotCallSendToSaasWhenLocalEnv' => [ | ||
'config' => [ | ||
'wp_env' => 'local', | ||
'remove_unused_css' => 0, | ||
'factories' => [1], | ||
'license_expired' => false, | ||
'home_url' => 'http://example.com/', | ||
], | ||
'expected' => 0, | ||
], | ||
'testShouldNotCallSendToSaasWhenRemoveUnusedCssEnabled' => [ | ||
'config' => [ | ||
'wp_env' => 'production', | ||
'remove_unused_css' => 1, | ||
'license_expired' => false, | ||
'factories' => [1], | ||
'home_url' => 'http://example.com/', | ||
], | ||
'expected' => 0, | ||
], | ||
'testShouldNotCallSendToSaasWhenFactoriesAreEmpty' => [ | ||
'config' => [ | ||
'wp_env' => 'production', | ||
'remove_unused_css' => 0, | ||
'license_expired' => false, | ||
'factories' => [], | ||
'home_url' => 'http://example.com/', | ||
], | ||
'expected' => 0, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/Integration/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\tests\Integration\inc\Engine\Common\PerformanceHints\WarmUp\Subscriber; | ||
|
||
use Mockery; | ||
use Brain\Monkey\Functions; | ||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Common\PerformanceHints\WarmUp\APIClient; | ||
use WP_Rocket\Engine\Common\PerformanceHints\WarmUp\Controller; | ||
use WP_Rocket\Engine\Common\PerformanceHints\WarmUp\Queue; | ||
use WP_Rocket\Engine\License\API\User; | ||
use WP_Rocket\Tests\Integration\TestCase; | ||
|
||
/** | ||
* Test class covering \WP_Rocket\Engine\Common\PerformanceHints\WarmUp\Subscriber::warm_up_home | ||
* | ||
* @group PerformanceHints | ||
* @group WarmUp | ||
*/ | ||
class Test_WarmUpHome extends TestCase { | ||
/** | ||
* Test should do expected. | ||
* | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoExpected( $config, $expected ) { | ||
$options = Mockery::mock(Options_Data::class); | ||
$api_client = Mockery::mock(APIClient::class); | ||
$user = Mockery::mock(User::class); | ||
$queue = Mockery::mock(Queue::class); | ||
$controller = Mockery::mock(Controller::class, [$config['factories'], $options, $api_client, $user, $queue])->makePartial(); | ||
|
||
$controller->shouldReceive('send_to_saas') | ||
->andReturn($config['home_url']); | ||
|
||
Functions\expect( 'wp_get_environment_type' )->andReturn($config['wp_env']); | ||
|
||
$queue->shouldReceive('add_job_warmup') | ||
->times($expected); | ||
|
||
if ( 'local' !== $config['wp_env'] ) { | ||
$options->shouldReceive('get') | ||
->with('remove_unused_css', 0) | ||
->andReturn($config['remove_unused_css']); | ||
|
||
$user->shouldReceive( 'is_license_expired_grace_period' ) | ||
->once() | ||
->andReturn( $config['license_expired'] ); | ||
} | ||
|
||
add_action('rocket_after_clear_performance_hints_data', [$controller, 'warm_up_home']); | ||
|
||
do_action('rocket_after_clear_performance_hints_data'); | ||
|
||
remove_action('rocket_after_clear_performance_hints_data', [$controller, 'warm_up_home']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters