Changeset 54271 for trunk/tests/phpunit/tests/post/getPageByTitle.php
- Timestamp:
- 09/21/2022 05:27:12 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.