Tests: Add more fixtures to get_lastpostdate() and get_lastpostmodified() tests.

Follow-up to [48631].

Props munyagu.
See #47777.

git-svn-id: https://develop.svn.wordpress.org/trunk@48633 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-07-27 11:15:04 +00:00
parent 838f9884d7
commit fc62131e31
2 changed files with 89 additions and 28 deletions

View File

@ -9,31 +9,50 @@ class Tests_Post_GetLastPostDate extends WP_UnitTestCase {
* @ticket 47777
*/
public function test_get_lastpostdate() {
$post_post_date = '2020-01-30 16:09:28';
$book_post_date = '2019-02-28 18:11:30';
$post_post_date_first = '2020-01-30 16:09:28';
$post_post_date_last = '2020-02-28 16:09:28';
$book_post_date_first = '2019-03-30 18:11:30';
$book_post_date_last = '2019-04-30 18:11:30';
// Register book post type.
register_post_type( 'book', array( 'has_archive' => true ) );
// Create a simple post.
$simple_post_id = self::factory()->post->create(
$simple_post_id_first = self::factory()->post->create(
array(
'post_title' => 'Simple Post',
'post_title' => 'Simple Post First',
'post_type' => 'post',
'post_date' => $post_post_date,
'post_date' => $post_post_date_first,
)
);
$simple_post_id_last = self::factory()->post->create(
array(
'post_title' => 'Simple Post Last',
'post_type' => 'post',
'post_date' => $post_post_date_last,
)
);
// Create custom type post.
$book_cpt_id = self::factory()->post->create(
$book_cpt_id_first = self::factory()->post->create(
array(
'post_title' => 'Book CPT',
'post_title' => 'Book CPT First',
'post_type' => 'book',
'post_date' => $book_post_date,
'post_date' => $book_post_date_first,
)
);
$this->assertEquals( $post_post_date, get_lastpostdate( 'blog', 'post' ) );
$this->assertEquals( $book_post_date, get_lastpostdate( 'blog', 'book' ) );
$book_cpt_id_last = self::factory()->post->create(
array(
'post_title' => 'Book CPT Last',
'post_type' => 'book',
'post_date' => $book_post_date_last,
)
);
$this->assertEquals( $post_post_date_last, get_lastpostdate( 'blog', 'post' ) );
$this->assertEquals( $book_post_date_last, get_lastpostdate( 'blog', 'book' ) );
}
}

View File

@ -11,30 +11,50 @@ class Tests_Post_GetLastPostModified extends WP_UnitTestCase {
public function test_get_lastpostmodified() {
global $wpdb;
$post_post_date = '2020-01-30 16:09:28';
$post_post_modified = '2020-02-28 17:10:29';
$post_post_date_first = '2020-01-30 16:09:28';
$post_post_modified_first = '2020-02-28 17:10:29';
$post_post_date_last = '2020-03-30 18:11:30';
$post_post_modified_last = '2020-04-30 19:12:31';
$book_post_date = '2019-03-30 20:09:28';
$book_post_modified = '2019-04-30 21:10:29';
$book_post_date_first = '2019-05-30 20:09:28';
$book_post_modified_first = '2019-06-30 21:10:29';
$book_post_date_last = '2019-07-30 22:11:30';
$book_post_modified_last = '2019-08-30 23:12:31';
// Register book post type.
register_post_type( 'book', array( 'has_archive' => true ) );
// Create a simple post.
$simple_post_id = self::factory()->post->create(
$simple_post_id_first = self::factory()->post->create(
array(
'post_title' => 'Simple Post',
'post_title' => 'Simple Post First',
'post_type' => 'post',
'post_date' => $post_post_date,
'post_date' => $post_post_date_first,
)
);
$simple_post_id_last = self::factory()->post->create(
array(
'post_title' => 'Simple Post Last',
'post_type' => 'post',
'post_date' => $post_post_date_last,
)
);
// Create custom type post.
$book_cpt_id = self::factory()->post->create(
$book_cpt_id_first = self::factory()->post->create(
array(
'post_title' => 'Book CPT',
'post_title' => 'Book CPT First',
'post_type' => 'book',
'post_date' => $book_post_date,
'post_date' => $book_post_date_first,
)
);
$book_cpt_id_last = self::factory()->post->create(
array(
'post_title' => 'Book CPT Last',
'post_type' => 'book',
'post_date' => $book_post_date_last,
)
);
@ -42,26 +62,48 @@ class Tests_Post_GetLastPostModified extends WP_UnitTestCase {
$wpdb->update(
$wpdb->posts,
array(
'post_modified' => $post_post_modified,
'post_modified_gmt' => $post_post_modified,
'post_modified' => $post_post_modified_first,
'post_modified_gmt' => $post_post_modified_first,
),
array(
'ID' => $simple_post_id,
'ID' => $simple_post_id_first,
)
);
$wpdb->update(
$wpdb->posts,
array(
'post_modified' => $book_post_modified,
'post_modified_gmt' => $book_post_modified,
'post_modified' => $post_post_modified_last,
'post_modified_gmt' => $post_post_modified_last,
),
array(
'ID' => $book_cpt_id,
'ID' => $simple_post_id_last,
)
);
$this->assertEquals( $post_post_modified, get_lastpostmodified( 'blog', 'post' ) );
$this->assertEquals( $book_post_modified, get_lastpostmodified( 'blog', 'book' ) );
$wpdb->update(
$wpdb->posts,
array(
'post_modified' => $book_post_modified_first,
'post_modified_gmt' => $book_post_modified_first,
),
array(
'ID' => $book_cpt_id_first,
)
);
$wpdb->update(
$wpdb->posts,
array(
'post_modified' => $book_post_modified_last,
'post_modified_gmt' => $book_post_modified_last,
),
array(
'ID' => $book_cpt_id_last,
)
);
$this->assertEquals( $post_post_modified_last, get_lastpostmodified( 'blog', 'post' ) );
$this->assertEquals( $book_post_modified_last, get_lastpostmodified( 'blog', 'book' ) );
}
}