-
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.
3.16 bug the warm up of lcpatf is not triggered when clicking clear c…
…ritical images in the admin (#6517)
- Loading branch information
Showing
4 changed files
with
133 additions
and
9 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
76 changes: 76 additions & 0 deletions
76
tests/Fixtures/inc/Engine/Media/AboveTheFold/Admin/Controller/truncateAtfAdmin.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,76 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldTruncateDb' => [ | ||
'config' => [ | ||
'rows' => [ | ||
[ | ||
'status' => 'completed', | ||
'url' => 'http://example.org', | ||
'lcp' => json_encode((object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
]), | ||
'viewport' => json_encode([ | ||
0 => (object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
], | ||
]), | ||
], | ||
[ | ||
'status' => 'completed', | ||
'url' => 'http://example.org/page-1/', | ||
'lcp' => json_encode((object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
]), | ||
'viewport' => json_encode([ | ||
0 => (object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
], | ||
]) | ||
] | ||
], | ||
'rocket_manage_options' => true, | ||
], | ||
'expected' => 0 | ||
], | ||
'testShouldNotTruncateDb' => [ | ||
'config' => [ | ||
'rows' => [ | ||
[ | ||
'status' => 'completed', | ||
'url' => 'http://example.org', | ||
'lcp' => json_encode((object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
]), | ||
'viewport' => json_encode([ | ||
0 => (object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
], | ||
]), | ||
], | ||
[ | ||
'status' => 'completed', | ||
'url' => 'http://example.org/page-1/', | ||
'lcp' => json_encode((object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
]), | ||
'viewport' => json_encode([ | ||
0 => (object)[ | ||
'type' => 'img', | ||
'src' => 'http://example.org/wp-content/uploads/image.jpg', | ||
], | ||
]) | ||
] | ||
], | ||
'rocket_manage_options' => false, | ||
], | ||
'expected' => 2 | ||
], | ||
]; |
48 changes: 48 additions & 0 deletions
48
tests/Integration/inc/Engine/Media/AboveTheFold/Admin/Controller/truncateAtfAdmin.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,48 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Integration\inc\Engine\Media\AboveTheFold\Admin\Controller; | ||
|
||
use WP_Rocket\Tests\Integration\DBTrait; | ||
use WP_Rocket\Tests\Integration\TestCase; | ||
use Brain\Monkey\Functions; | ||
use Mockery; | ||
use WP_Rocket\Engine\Media\AboveTheFold\WarmUp\Controller; | ||
|
||
/** | ||
* @covers \WP_Rocket\Engine\Media\AboveTheFold\Admin\Controller::truncate_atf_admin | ||
* | ||
* @group AboveTheFold | ||
*/ | ||
class Test_TruncateAtfAdmin extends TestCase { | ||
use DBTrait; | ||
|
||
protected $path_to_test_data = '/inc/Engine/Media/AboveTheFold/Admin/Controller/truncateAtfAdmin.php'; | ||
|
||
protected $config; | ||
public function set_up() { | ||
parent::set_up(); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoAsExpected( $config, $expected ) { | ||
$this->config = $config; | ||
$container = apply_filters( 'rocket_container', null ); | ||
$warm_up_controller = Mockery::mock( Controller::class ); | ||
foreach ( $this->config['rows'] as $row ) { | ||
self::addLcp( $row ); | ||
} | ||
Functions\expect( 'current_user_can' )->once()->with('rocket_manage_options')->andReturn($config['rocket_manage_options']); | ||
do_action( 'rocket_saas_clean_all' ); | ||
|
||
$atf_query = $container->get( 'atf_query' ); | ||
$result_atf_after_clean = $atf_query->query(); | ||
|
||
$this->assertCount( $expected, $result_atf_after_clean ); | ||
if ( ! $expected ) { | ||
$this->assertSame( 1, did_action( 'rocket_after_clear_atf' ) ); | ||
} | ||
|
||
} | ||
} |