-
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.
Closes #6432: Adds conditions to bail out from beacon
- Loading branch information
Showing
8 changed files
with
222 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
70 changes: 70 additions & 0 deletions
70
tests/Fixtures/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.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,70 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldReturnErrorWhenNotAllowed' => [ | ||
'config' => [ | ||
'filter' => false, | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
'post' => [ | ||
'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), | ||
'action' => 'rocket_check_lcp', | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
], | ||
'row' => [], | ||
], | ||
'expected' => [ | ||
'result' => false, | ||
], | ||
], | ||
'testShouldReturnExists' => [ | ||
'config' => [ | ||
'filter' => true, | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
'post' => [ | ||
'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), | ||
'action' => 'rocket_check_lcp', | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
], | ||
'row' => [ | ||
'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', | ||
], | ||
] ), | ||
], | ||
'row_exists' => true, | ||
], | ||
'expected' => [ | ||
'result' => true, | ||
], | ||
], | ||
'testShouldReturnNotExists' => [ | ||
'config' => [ | ||
'filter' => true, | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
'post' => [ | ||
'rocket_lcp_nonce' => wp_create_nonce( 'rocket_lcp' ), | ||
'action' => 'rocket_check_lcp', | ||
'url' => 'http://example.org', | ||
'is_mobile' => false, | ||
], | ||
'row' => [], | ||
'row_exists' => false, | ||
], | ||
'expected' => [ | ||
'result' => false, | ||
], | ||
], | ||
]; |
53 changes: 53 additions & 0 deletions
53
tests/Integration/inc/Engine/Media/AboveTheFold/AJAX/Subscriber/checkLcpData.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,53 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Integration\Inc\Engine\Media\AboveTheFold\AJAX\Subscriber; | ||
|
||
use WP_Rocket\Tests\Integration\AjaxTestCase; | ||
|
||
/** | ||
* @covers WP_Rocket\Engine\Media\AboveTheFold\AJAX\Subscriber::check_lcp_data | ||
* | ||
* @group AboveTheFold | ||
*/ | ||
class Test_CheckLcpData extends AjaxTestCase { | ||
private $allowed; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->action = 'rocket_check_lcp'; | ||
} | ||
|
||
/** | ||
* $_POST is cleared in parent method | ||
* | ||
* @return void | ||
*/ | ||
public function tear_down() { | ||
remove_filter( 'rocket_above_the_fold_optimization', [ $this, 'set_allowed' ] ); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnExpected( $config, $expected ) { | ||
$_POST = $config['post']; | ||
|
||
$this->allowed = $config['filter']; | ||
|
||
add_filter( 'rocket_above_the_fold_optimization', [ $this, 'set_allowed' ] ); | ||
|
||
if ( ! empty( $config['row'] ) ) { | ||
self::addLcp( $config['row'] ); | ||
} | ||
|
||
$result = $this->callAjaxAction(); | ||
|
||
$this->assertSame( $expected['result'], $result->success ); | ||
} | ||
public function set_allowed() { | ||
return $this->allowed; | ||
} | ||
} |