Skip to content

Commit

Permalink
Add test for is_mobile method, --closes #6697
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jun 28, 2024
1 parent 7df1552 commit 918f3c0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
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 918f3c0

Please sign in to comment.