mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Fixes bug where an invalid Last-Modified value would be returned in feed requests for sites that had 0 items to return. Comment or post feeds will now return the current timestamp as the Last-Modified header value. Example: a request for the comments feed for a site without any comments. Replaced use of the local static variable `$cache_lastcommentmodified` to store the modified date in `get_lastcommentmodified()` with the Object Cache API. The `get_lastcommentmodified()` function returns early if there is a cached value and returns `false` if there where no comments found. Introduced `_clear_modified_cache_on_transition_comment_status()` to flush the `lastcommentmodified` cache key when a comment enters or leaves approval status. In `get_lastpostmodified()` return early if there is a cached value and return `false` if there are no posts found. Props swissspidy, rachelbaker, dllh, leobaiano. Fixes #38027. git-svn-id: https://develop.svn.wordpress.org/trunk@38925 602fd350-edb4-49c9-b593-d223f7449a82
119 lines
3.9 KiB
PHP
119 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group comment
|
|
* @group 38027
|
|
*/
|
|
class Tests_Comment_Last_Modified extends WP_UnitTestCase {
|
|
public function test_no_comments() {
|
|
$this->assertFalse( get_lastcommentmodified() );
|
|
}
|
|
|
|
public function test_default_timezone() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
$this->assertSame( strtotime( '2000-01-01 10:00:00' ), strtotime( get_lastcommentmodified() ) );
|
|
}
|
|
|
|
public function test_server_timezone() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
$this->assertSame( strtotime( '2000-01-01 10:00:00' ), strtotime( get_lastcommentmodified() ) );
|
|
}
|
|
|
|
public function test_blog_timezone() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
$this->assertSame( '2000-01-01 11:00:00', get_lastcommentmodified( 'blog' ) );
|
|
}
|
|
|
|
public function test_gmt_timezone() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
$this->assertSame( strtotime( '2000-01-01 10:00:00' ), strtotime( get_lastcommentmodified( 'GMT' ) ) );
|
|
}
|
|
|
|
public function test_unknown_timezone() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
$this->assertFalse( get_lastcommentmodified( 'foo' ) );
|
|
}
|
|
|
|
public function test_data_is_cached() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2015-04-01 11:00:00',
|
|
'comment_date_gmt' => '2015-04-01 10:00:00',
|
|
) );
|
|
|
|
get_lastcommentmodified();
|
|
$this->assertSame( strtotime( '2015-04-01 10:00:00' ), strtotime( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) ) );
|
|
}
|
|
|
|
public function test_cache_is_cleared() {
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-01 11:00:00',
|
|
'comment_date_gmt' => '2000-01-01 10:00:00',
|
|
) );
|
|
|
|
get_lastcommentmodified();
|
|
|
|
$this->assertSame( strtotime( '2000-01-01 10:00:00' ), strtotime( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) ) );
|
|
|
|
self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-02 11:00:00',
|
|
'comment_date_gmt' => '2000-01-02 10:00:00',
|
|
) );
|
|
|
|
$this->assertFalse( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) );
|
|
$this->assertSame( strtotime( '2000-01-02 10:00:00' ), strtotime( get_lastcommentmodified() ) );
|
|
$this->assertSame( strtotime( '2000-01-02 10:00:00' ), strtotime( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) ) );
|
|
}
|
|
|
|
public function test_cache_is_cleared_when_comment_is_trashed() {
|
|
$comment_1 = self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '1998-01-01 11:00:00',
|
|
'comment_date_gmt' => '1998-01-01 10:00:00',
|
|
) );
|
|
|
|
$comment_2 = self::factory()->comment->create_and_get( array(
|
|
'comment_status' => 1,
|
|
'comment_date' => '2000-01-02 11:00:00',
|
|
'comment_date_gmt' => '2000-01-02 10:00:00',
|
|
) );
|
|
|
|
get_lastcommentmodified();
|
|
|
|
$this->assertSame( strtotime( '2000-01-02 10:00:00' ), strtotime( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) ) );
|
|
|
|
wp_trash_comment( $comment_2->comment_ID );
|
|
|
|
$this->assertFalse( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) );
|
|
$this->assertSame( strtotime( '1998-01-01 10:00:00' ), strtotime( get_lastcommentmodified() ) );
|
|
$this->assertSame( strtotime( '1998-01-01 10:00:00' ), strtotime( wp_cache_get( 'lastcommentmodified:server', 'timeinfo' ) ) );
|
|
}
|
|
}
|