wordpress-develop/tests/phpunit/tests/post/getLastPostDate.php
Sergey Biryukov 164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00

59 lines
1.4 KiB
PHP

<?php
/**
* @group post
*/
class Tests_Post_GetLastPostDate extends WP_UnitTestCase {
/**
* @ticket 47777
*/
public function test_get_lastpostdate() {
$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_first = self::factory()->post->create(
array(
'post_title' => 'Simple Post First',
'post_type' => 'post',
'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_first = self::factory()->post->create(
array(
'post_title' => 'Book CPT First',
'post_type' => 'book',
'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,
)
);
$this->assertSame( $post_post_date_last, get_lastpostdate( 'blog', 'post' ) );
$this->assertSame( $book_post_date_last, get_lastpostdate( 'blog', 'book' ) );
}
}