-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c023ef9
commit 47f2f83
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
tests/Fixtures/inc/Engine/Cache/PostSubscriber/disableCacheOnNotValidPages.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 | ||
|
||
return [ | ||
'test_data' => [ | ||
'testIsNotInPostPage' => [ | ||
'config' => [ | ||
'is_singular' => false, | ||
], | ||
'can_cache' => true, | ||
], | ||
'testValidPostPage' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 1, | ||
'current_post_link' => 'http://example.com/test1', | ||
'current_page_url' => 'http://example.com/test1', | ||
], | ||
'can_cache' => true, | ||
], | ||
'testValidPostPageWithPagination' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 1, | ||
'current_post_link' => 'http://example.com/test1', | ||
'current_page_url' => 'http://example.com/test1/page/2', | ||
'page' => 2, | ||
], | ||
'can_cache' => true, | ||
], | ||
'testEmptyPostId' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 0, | ||
'current_post_link' => '', | ||
'current_post_url' => 'http://example.com/test1', | ||
], | ||
'can_cache' => true, | ||
], | ||
'testNotValidPostPage' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 1, | ||
'current_post_link' => 'http://example.com/test1', | ||
'current_post_url' => 'http://example.com/additional-query/test1', | ||
], | ||
'can_cache' => false, | ||
], | ||
'testNotValidPostPageWithPagination' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 1, | ||
'current_post_link' => 'http://example.com/test1', | ||
'current_page_url' => 'http://example.com/additional-query/test1/page/2', | ||
'page' => 2, | ||
], | ||
'can_cache' => false, | ||
], | ||
'testValidPostPageWithNonLatinCharactersInUrl' => [ | ||
'config' => [ | ||
'is_singular' => true, | ||
'current_post_id' => 1, | ||
'current_post_link' => 'http://example.com/%D0%BF%D1%80%D0%BE%D0%B4%D1%83%D0%BA%D1%82%D0%BE%D0%B2%D0%B0-%D0%BA%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F/', | ||
'current_page_url' => 'http://example.com/продуктова-категория/', | ||
], | ||
'can_cache' => true, | ||
], | ||
], | ||
]; |
42 changes: 42 additions & 0 deletions
42
tests/Unit/inc/Engine/Cache/PostSubscriber/disableCacheOnNotValidPages.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,42 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\Engine\Cache\PostSubscriber; | ||
|
||
use Brain\Monkey\Functions; | ||
use WP_Rocket\Engine\Cache\PostSubscriber; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
|
||
/** | ||
* Test class covering PostSubscriber::disable_cache_on_not_valid_pages | ||
* @covers PostSubscriber::disable_cache_on_not_valid_pages | ||
* | ||
* @uses PostSubscriber::is_not_valid_page | ||
* | ||
* @group Cache | ||
*/ | ||
class Test_DisableCacheOnNotValidPages extends TestCase { | ||
Check failure on line 17 in tests/Unit/inc/Engine/Cache/PostSubscriber/disableCacheOnNotValidPages.php
|
||
private $subscriber; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->subscriber = new PostSubscriber(); | ||
} | ||
|
||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnExpected( $config, $can_cache ) { | ||
Functions\expect( 'is_singular' )->once()->andReturn( ! empty( $config['is_singular'] ) ); | ||
Functions\when( 'get_queried_object_id' )->justReturn( $config['current_post_id'] ?? 0 ); | ||
|
||
Functions\when( 'get_permalink' )->justReturn( $config['current_post_link'] ?? '' ); | ||
Functions\when( 'add_query_arg' )->justReturn( '' ); | ||
Functions\when( 'home_url' )->justReturn( $config['current_page_url'] ?? '' ); | ||
Functions\when( 'is_paged' )->justReturn( ! empty( $config['page'] ) ); | ||
Functions\when( 'get_query_var' )->justReturn( $config['page'] ?? 0 ); | ||
|
||
$this->assertSame( $can_cache, $this->subscriber->disable_cache_on_not_valid_pages( true ) ); | ||
} | ||
} |