diff --git a/inc/Engine/Media/AboveTheFold/WarmUp/Controller.php b/inc/Engine/Media/AboveTheFold/WarmUp/Controller.php index 8493cc1eac..86750d4239 100644 --- a/inc/Engine/Media/AboveTheFold/WarmUp/Controller.php +++ b/inc/Engine/Media/AboveTheFold/WarmUp/Controller.php @@ -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 ); } } diff --git a/tests/Fixtures/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php b/tests/Fixtures/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php new file mode 100644 index 0000000000..5bcc39b952 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php @@ -0,0 +1,20 @@ + [ + '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', + ], +]; diff --git a/tests/Unit/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php b/tests/Unit/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php new file mode 100644 index 0000000000..3d84363cbf --- /dev/null +++ b/tests/Unit/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php @@ -0,0 +1,69 @@ +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']); + } +}