| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group post |
| | 5 | */ |
| | 6 | class Tests_Post_GetLastPostModified extends WP_UnitTestCase { |
| | 7 | /** |
| | 8 | * @ticket 47777 |
| | 9 | */ |
| | 10 | public function test_get_lastpostmodified() { |
| | 11 | $post_post_date = '2018-01-30 16:09:28'; |
| | 12 | $post_post_modified_date = '2018-02-28 17:10:29'; |
| | 13 | |
| | 14 | $book_post_date = '2019-03-30 18:11:30'; |
| | 15 | $book_post_modified_date = '2019-04-30 19:12:31'; |
| | 16 | |
| | 17 | // Register book post type. |
| | 18 | register_post_type( 'book', array( 'has_archive' => true ) ); |
| | 19 | |
| | 20 | // Create a simple post. |
| | 21 | $simple_post_id = self::factory()->post->create( |
| | 22 | array( |
| | 23 | 'post_title' => 'Simple Post', |
| | 24 | 'post_type' => 'post', |
| | 25 | 'post_date' => $post_post_date, |
| | 26 | ) |
| | 27 | ); |
| | 28 | |
| | 29 | // Create custom type post |
| | 30 | $book_cpt_id = self::factory()->post->create( |
| | 31 | array( |
| | 32 | 'post_title' => 'Book CPT', |
| | 33 | 'post_type' => 'book', |
| | 34 | 'post_date' => $book_post_date |
| | 35 | ) |
| | 36 | ); |
| | 37 | |
| | 38 | // Update `post_modified` and `post_modified_gmt`. |
| | 39 | global $wpdb; |
| | 40 | |
| | 41 | $wpdb->update( |
| | 42 | $wpdb->posts, |
| | 43 | array( |
| | 44 | 'post_modified' => $post_post_modified_date, |
| | 45 | 'post_modified_gmt' => $post_post_modified_date, |
| | 46 | ), |
| | 47 | array( |
| | 48 | 'ID' => $simple_post_id, |
| | 49 | ) |
| | 50 | ); |
| | 51 | |
| | 52 | $wpdb->update( |
| | 53 | $wpdb->posts, |
| | 54 | array( |
| | 55 | 'post_modified' => $book_post_modified_date, |
| | 56 | 'post_modified_gmt' => $book_post_modified_date, |
| | 57 | ), |
| | 58 | array( |
| | 59 | 'ID' => $book_cpt_id, |
| | 60 | ) |
| | 61 | ); |
| | 62 | |
| | 63 | // Delete cache to get the updated modified date. |
| | 64 | wp_cache_delete( $simple_post_id, 'posts' ); |
| | 65 | wp_cache_delete( $book_cpt_id, 'posts' ); |
| | 66 | |
| | 67 | $post_lastpost_modified = get_lastpostmodified( 'blog', 'post' ); |
| | 68 | $book_lastpost_modified = get_lastpostmodified( 'blog', 'book' ); |
| | 69 | |
| | 70 | $this->assertEquals( $post_post_modified_date, $post_lastpost_modified ); |
| | 71 | $this->assertEquals( $book_post_modified_date, $book_lastpost_modified ); |
| | 72 | } |
| | 73 | } |