Skip to content

Commit

Permalink
Merge branch 'release/3.6.0' into follow-up-1642
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz authored Nov 18, 2024
2 parents c005012 + 89e4080 commit 8579b36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/optimization-detective/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function od_can_optimize_response(): bool {
current_user_can( 'customize' ) ||
// Page caching plugins can only reliably be told to invalidate a cached page when a post is available to trigger
// the relevant actions on.
null !== od_get_cache_purge_post_id()
null === od_get_cache_purge_post_id()
);

/**
Expand Down
31 changes: 24 additions & 7 deletions plugins/optimization-detective/tests/test-optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,35 @@ public function test_od_maybe_add_template_output_buffer_filter_with_query_var_t
*/
public function data_provider_test_od_can_optimize_response(): array {
return array(
'homepage' => array(
'home_as_anonymous' => array(
'set_up' => function (): void {
$this->go_to( home_url( '/' ) );
},
'expected' => true,
),
'homepage_filtered' => array(
'home_filtered_as_anonymous' => array(
'set_up' => function (): void {
$this->go_to( home_url( '/' ) );
add_filter( 'od_can_optimize_response', '__return_false' );
},
'expected' => false,
),
'search' => array(
'singular_as_anonymous' => array(
'set_up' => function (): void {
$posts = get_posts();
$this->assertInstanceOf( WP_Post::class, $posts[0] );
$this->go_to( get_permalink( $posts[0] ) );
},
'expected' => true,
),
'search_as_anonymous' => array(
'set_up' => function (): void {
self::factory()->post->create( array( 'post_title' => 'Hello' ) );
$this->go_to( home_url( '?s=Hello' ) );
},
'expected' => false,
),
'customizer_preview' => array(
'home_customizer_preview_as_anonymous' => array(
'set_up' => function (): void {
$this->go_to( home_url( '/' ) );
global $wp_customize;
Expand All @@ -215,21 +223,28 @@ public function data_provider_test_od_can_optimize_response(): array {
},
'expected' => false,
),
'post_request' => array(
'home_post_request_as_anonymous' => array(
'set_up' => function (): void {
$this->go_to( home_url( '/' ) );
$_SERVER['REQUEST_METHOD'] = 'POST';
},
'expected' => false,
),
'subscriber_user' => array(
'home_as_subscriber' => array(
'set_up' => function (): void {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
$this->go_to( home_url( '/' ) );
},
'expected' => true,
),
'admin_user' => array(
'empty_author_page_as_anonymous' => array(
'set_up' => function (): void {
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
$this->go_to( get_author_posts_url( $user_id ) );
},
'expected' => false,
),
'home_as_admin' => array(
'set_up' => function (): void {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
$this->go_to( home_url( '/' ) );
Expand All @@ -243,10 +258,12 @@ public function data_provider_test_od_can_optimize_response(): array {
* Test od_can_optimize_response().
*
* @covers ::od_can_optimize_response
* @covers ::od_get_cache_purge_post_id
*
* @dataProvider data_provider_test_od_can_optimize_response
*/
public function test_od_can_optimize_response( Closure $set_up, bool $expected ): void {
self::factory()->post->create(); // Make sure there is at least one post in the DB.
$set_up();
$this->assertSame( $expected, od_can_optimize_response() );
}
Expand Down

0 comments on commit 8579b36

Please sign in to comment.