Skip to content

Commit

Permalink
:closes: Fix issue with warm up link for homepage (#6742)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathieu Lamiot <[email protected]>
  • Loading branch information
Khadreal and MathieuLamiot authored Jul 1, 2024
1 parent c827f94 commit cb820e9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
7 changes: 6 additions & 1 deletion inc/Engine/Media/AboveTheFold/WarmUp/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ public function add_wpr_imagedimensions_query_arg( string $url ): string {
}

/**
* Check if the current request is for mobile.
* Check if the mobile cache is set.
*
* @return bool
*/
private function is_mobile(): bool {
$plugin_version = (string) get_rocket_option( 'version', '' );
if ( ! $plugin_version ) { // We are warming up a fresh installation. Options are not set yet.
return true;
}

return $this->options->get( 'cache_mobile', 0 ) && $this->options->get( 'do_caching_mobile_files', 0 );
}
}
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',
],
];
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']);
}
}

0 comments on commit cb820e9

Please sign in to comment.