-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Tabrisrp <[email protected]> Co-authored-by: WordPressFan <[email protected]>
- Loading branch information
1 parent
a4a724d
commit 7a90e86
Showing
7 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
22 changes: 22 additions & 0 deletions
22
tests/Fixtures/inc/Engine/Media/AboveTheFold/Admin/Controller/truncateOnUpdate.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,22 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldDoNothingWhenVersionUnder3.16.1' => [ | ||
'config' => [ | ||
'filter' => true, | ||
'new_version' => '3.16.2', | ||
'old_version' => '3.16.1', | ||
'not_completed' => 0, | ||
], | ||
'expected' => false, | ||
], | ||
'testShouldTruncateWhenVersion3.16.1AndHigher' => [ | ||
'config' => [ | ||
'filter' => true, | ||
'new_version' => '3.16.1', | ||
'old_version' => '3.15.0', | ||
'not_completed' => 0, | ||
], | ||
'expected' => true, | ||
], | ||
]; |
56 changes: 56 additions & 0 deletions
56
tests/Unit/inc/Engine/Media/AboveTheFold/Admin/Controller/truncateOnUpdate.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,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\Engine\Media\AboveTheFold\Admin\Controller; | ||
|
||
use Mockery; | ||
use WP_Rocket\Engine\Media\AboveTheFold\Context\Context; | ||
use WP_Rocket\Engine\Media\AboveTheFold\Database\Tables\AboveTheFold as ATFTable; | ||
use WP_Rocket\Engine\Media\AboveTheFold\Database\Queries\AboveTheFold as ATFQuery; | ||
use WP_Rocket\Engine\Media\AboveTheFold\Admin\Controller; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
|
||
/** | ||
* Test class covering WP_Rocket\Engine\Media\AboveTheFold\Admin\Controller::truncate_atf | ||
* | ||
* @group ATF | ||
*/ | ||
class TestTruncateOnUpdate extends TestCase { | ||
private $controller; | ||
private $query; | ||
private $table; | ||
private $context; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->query = $this->createMock( ATFQuery::class ); | ||
$this->table = $this->createMock( ATFTable::class ); | ||
$this->context = Mockery::mock( Context::class ); | ||
$this->controller = new Controller( $this->table, $this->query, $this->context ); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoExpected( $config, $expected ) { | ||
$this->context->shouldReceive( 'is_allowed' ) | ||
->atMost() | ||
->once() | ||
->andReturn( $config['filter'] ); | ||
|
||
if ( ! $expected ) { | ||
$this->query->expects( $this->never() ) | ||
->method( 'get_not_completed_count' ); | ||
} else { | ||
$this->query->expects( $this->once() ) | ||
->method( 'get_not_completed_count' ) | ||
->willReturn( $config['not_completed'] ); | ||
|
||
$this->table->expects( $this->once() ) | ||
->method( 'truncate_atf_table' ); | ||
} | ||
|
||
$this->controller->truncate_on_update( $config['new_version'], $config['old_version'] ); | ||
} | ||
} |
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