-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:closes: Fix issue with warm up link for homepage (#6742)
Co-authored-by: Mathieu Lamiot <[email protected]>
- Loading branch information
1 parent
c827f94
commit cb820e9
Showing
3 changed files
with
95 additions
and
1 deletion.
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
20 changes: 20 additions & 0 deletions
20
tests/Fixtures/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.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,20 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldCallATFQueueOnce' => [ | ||
'config' => [ | ||
'url' => 'http://example.com', | ||
'device' => 'desktop', | ||
'get_rocket_option' => 'true' | ||
], | ||
'expected' => 'http://example.com', | ||
], | ||
'testShouldCallATFQueueTwice' => [ | ||
'config' => [ | ||
'device' => 'mobile', | ||
'url' => 'http://example.com', | ||
'get_rocket_option' => '' | ||
], | ||
'expected' => 'http://example.com/?wpr_imagedimensions=1', | ||
], | ||
]; |
69 changes: 69 additions & 0 deletions
69
tests/Unit/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.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,69 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\tests\Unit\inc\Engine\Media\AboveTheFold\WarmUp\Controller; | ||
|
||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Common\Context\ContextInterface; | ||
use WP_Rocket\Engine\License\API\User; | ||
use WP_Rocket\Engine\Media\AboveTheFold\WarmUp\APIClient; | ||
use WP_Rocket\Engine\Media\AboveTheFold\WarmUp\Controller; | ||
use WP_Rocket\Engine\Media\AboveTheFold\WarmUp\Queue; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
use Brain\Monkey\Functions; | ||
use Mockery; | ||
|
||
class sendToSass extends TestCase { | ||
private $user; | ||
private $controller; | ||
private $context; | ||
private $queue; | ||
private $options; | ||
|
||
private $api_client; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->context = Mockery::mock( ContextInterface::class ); | ||
$this->options = Mockery::mock( Options_Data::class ); | ||
$this->api_client = Mockery::mock( APIClient::class ); | ||
$this->user = Mockery::mock( User::class ); | ||
$this->queue = Mockery::mock( Queue::class ); | ||
$this->controller = new Controller( $this->context, $this->options, $this->api_client, $this->user, $this->queue ); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnExpected( $config, $expected ) { | ||
$this->options->shouldReceive('get') | ||
->with('cache_mobile', 0) | ||
->andReturn(0); | ||
|
||
if('desktop' === $config['device']) { | ||
Functions\expect( 'get_rocket_option' ) | ||
->once() | ||
->with( 'version', '' ) | ||
->andReturn( true ); | ||
} | ||
|
||
$this->api_client->shouldReceive('add_to_atf_queue') | ||
->with('http://example.com') | ||
->once() | ||
->andReturn([$config['url'], []]); | ||
|
||
if('mobile' === $config['device']) { | ||
Functions\expect( 'get_rocket_option' ) | ||
->once() | ||
->with( 'version', '' ) | ||
->andReturn( '' ); | ||
|
||
$this->api_client->shouldReceive('add_to_atf_queue') | ||
->with('http://example.com', $config['device']) | ||
->once() | ||
->andReturn([$config['url'], []]); | ||
} | ||
|
||
$this->controller->send_to_saas($config['url']); | ||
} | ||
} |