From 918f3c0fa78cf42f23795ea4f4dc194ac5faf784 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Fri, 28 Jun 2024 14:13:36 +0100 Subject: [PATCH] Add test for is_mobile method, --closes #6697 --- .../WarmUp/Controller/sendToSass.php | 20 ++++++ .../WarmUp/Controller/sendToSass.php | 69 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/Fixtures/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php create mode 100644 tests/Unit/inc/Engine/Media/AboveTheFold/WarmUp/Controller/sendToSass.php 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']); + } +}