Changeset 54271
- Timestamp:
- 09/21/2022 05:27:12 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r54267 r54271 5776 5776 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { 5777 5777 $args = array( 5778 ' post_title'=> $page_title,5778 'title' => $page_title, 5779 5779 'post_type' => $post_type, 5780 5780 'post_status' => get_post_stati(), … … 5783 5783 'update_post_meta_cache' => false, 5784 5784 'no_found_rows' => true, 5785 'orderby' => ' ID',5785 'orderby' => 'post_date ID', 5786 5786 'order' => 'ASC', 5787 5787 ); -
trunk/tests/phpunit/tests/post/getPageByTitle.php
r54242 r54271 6 6 */ 7 7 class Tests_Post_GetPageByTitle extends WP_UnitTestCase { 8 9 /** 10 * Generate shared fixtures. 11 * 12 * These are not used in the tests but are rather used to populate the 13 * posts table and ensure that the tests return the correct post object 14 * by design rather than through chance. 15 */ 16 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 17 // Fill the database with some pages. 18 $factory->post->create_many( 19 2, 20 array( 21 'post_type' => 'page', 22 ) 23 ); 24 25 // Fill the database with some attachments. 26 $factory->post->create_many( 27 2, 28 array( 29 'post_type' => 'attachment', 30 ) 31 ); 32 33 // Fill the database with some test post types. 34 register_post_type( 'wptests_pt' ); 35 $factory->post->create_many( 36 2, 37 array( 38 'post_type' => 'wptests_pt', 39 ) 40 ); 41 } 42 8 43 /** 9 44 * @ticket 36905 … … 42 77 43 78 $this->assertSame( $page, $found->ID ); 79 } 80 81 /** 82 * @ticket 36905 83 * @ticket 56609 84 */ 85 public function test_should_be_case_insensitive_match() { 86 $page = self::factory()->post->create( 87 array( 88 'post_type' => 'page', 89 'post_title' => 'Foo', 90 ) 91 ); 92 93 $found = get_page_by_title( 'foo' ); 94 95 $this->assertSame( $page, $found->ID ); 96 } 97 98 /** 99 * Test the oldest published post is matched first. 100 * 101 * Per the docs: in case of more than one post having the same title, 102 * it will check the oldest publication date, not the smallest ID. 103 * 104 * @ticket 36905 105 * @ticket 56609 106 */ 107 public function test_should_match_oldest_published_date_when_titles_match() { 108 self::factory()->post->create( 109 array( 110 'post_type' => 'page', 111 'post_title' => 'foo', 112 ) 113 ); 114 115 $old_page = self::factory()->post->create( 116 array( 117 'post_type' => 'page', 118 'post_title' => 'foo', 119 'post_date' => '1984-01-11 05:00:00', 120 ) 121 ); 122 123 $found = get_page_by_title( 'foo' ); 124 125 $this->assertSame( $old_page, $found->ID ); 44 126 } 45 127
Note: See TracChangeset
for help on using the changeset viewer.