getLastPostDate.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @group post
  4. */
  5. class Tests_Post_GetLastPostDate extends WP_UnitTestCase {
  6. /**
  7. * @ticket 47777
  8. */
  9. public function test_get_lastpostdate() {
  10. $post_post_date_first = '2020-01-30 16:09:28';
  11. $post_post_date_last = '2020-02-28 16:09:28';
  12. $book_post_date_first = '2019-03-30 18:11:30';
  13. $book_post_date_last = '2019-04-30 18:11:30';
  14. // Register book post type.
  15. register_post_type( 'book', array( 'has_archive' => true ) );
  16. // Create a simple post.
  17. $simple_post_id_first = self::factory()->post->create(
  18. array(
  19. 'post_title' => 'Simple Post First',
  20. 'post_type' => 'post',
  21. 'post_date' => $post_post_date_first,
  22. )
  23. );
  24. $simple_post_id_last = self::factory()->post->create(
  25. array(
  26. 'post_title' => 'Simple Post Last',
  27. 'post_type' => 'post',
  28. 'post_date' => $post_post_date_last,
  29. )
  30. );
  31. // Create custom type post.
  32. $book_cpt_id_first = self::factory()->post->create(
  33. array(
  34. 'post_title' => 'Book CPT First',
  35. 'post_type' => 'book',
  36. 'post_date' => $book_post_date_first,
  37. )
  38. );
  39. $book_cpt_id_last = self::factory()->post->create(
  40. array(
  41. 'post_title' => 'Book CPT Last',
  42. 'post_type' => 'book',
  43. 'post_date' => $book_post_date_last,
  44. )
  45. );
  46. $this->assertSame( $post_post_date_last, get_lastpostdate( 'blog', 'post' ) );
  47. $this->assertSame( $book_post_date_last, get_lastpostdate( 'blog', 'book' ) );
  48. }
  49. }