-
Notifications
You must be signed in to change notification settings - Fork 215
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
- Loading branch information
Showing
9 changed files
with
268 additions
and
45 deletions.
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
tests/Fixtures/inc/Engine/Preload/Admin/Settings/clearAndPreload.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,20 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldOnlyTruncateWhenPreloadDisabled' => [ | ||
'config' => [ | ||
'options' => [ | ||
'manual_preload' => 0, | ||
], | ||
], | ||
'expected' => false, | ||
], | ||
'testShouldPreloadHomepageAndSitemap' => [ | ||
'config' => [ | ||
'options' => [ | ||
'manual_preload' => 1, | ||
], | ||
], | ||
'expected' => true, | ||
], | ||
]; |
20 changes: 20 additions & 0 deletions
20
tests/Fixtures/inc/Engine/Preload/Admin/Settings/preloadHomepage.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,20 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldDoNothingWhenPreloadDisabled' => [ | ||
'config' => [ | ||
'options' => [ | ||
'manual_preload' => 0, | ||
], | ||
], | ||
'expected' => false, | ||
], | ||
'testShouldPreloadHomepage' => [ | ||
'config' => [ | ||
'options' => [ | ||
'manual_preload' => 1, | ||
], | ||
], | ||
'expected' => true, | ||
], | ||
]; |
68 changes: 68 additions & 0 deletions
68
tests/Unit/inc/Engine/Preload/Admin/Settings/clearAndPreload.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,68 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\Engine\Preload\Admin\Settings; | ||
|
||
use Brain\Monkey\Functions; | ||
use Mockery; | ||
use WP_Rocket\Admin\Options_Data; | ||
use WP_Rocket\Engine\Preload\Admin\Settings; | ||
use WP_Rocket\Engine\Preload\Controller\{LoadInitialSitemap, PreloadUrl}; | ||
use WP_Rocket\Engine\Preload\Database\Tables\Cache as CacheTable; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
|
||
/** | ||
* Test class covering \WP_Rocket\Engine\Preload\Admin\Settings::clear_and_preload | ||
* | ||
* @group Preload | ||
*/ | ||
class TestClearAndPreload extends TestCase { | ||
private $settings; | ||
private $options; | ||
private $preload_url; | ||
private $sitemap; | ||
private $cache; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->options = Mockery::mock( Options_Data::class ); | ||
$this->preload_url = Mockery::mock( PreloadUrl::class ); | ||
$this->sitemap = Mockery::mock( LoadInitialSitemap::class ); | ||
$this->cache = $this->createMock( CacheTable::class ); | ||
$this->settings = new Settings( | ||
$this->options, | ||
$this->preload_url, | ||
$this->sitemap, | ||
$this->cache | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoExpected( $config, $expected ) { | ||
Functions\when( 'home_url' )->justReturn( 'http://example.org/' ); | ||
|
||
$this->cache->expects( $this->once() ) | ||
->method( 'truncate_cache_table' ); | ||
|
||
$this->options->shouldReceive( 'get' ) | ||
->with( 'manual_preload', 0 ) | ||
->andReturn( $config['options']['manual_preload'] ); | ||
|
||
if ( $expected ) { | ||
$this->sitemap->shouldReceive( 'load_initial_sitemap' ) | ||
->once(); | ||
$this->preload_url->shouldReceive( 'preload_url' ) | ||
->once(); | ||
} else { | ||
$this->sitemap->shouldReceive( 'load_initial_sitemap' ) | ||
->never(); | ||
$this->preload_url->shouldReceive( 'preload_url' ) | ||
->never(); | ||
} | ||
|
||
$this->settings->clear_and_preload(); | ||
} | ||
} |
36 changes: 23 additions & 13 deletions
36
tests/Unit/inc/Engine/Preload/Admin/Settings/maybeDisplayPreloadNotice.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
Oops, something went wrong.