Changeset 36077
- Timestamp:
- 12/23/2015 07:38:29 PM (9 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link.php
r35497 r36077 99 99 100 100 /** 101 * @ticket 17807102 */103 function test_get_adjacent_post() {104 // Need some sample posts to test adjacency105 $post_one = self::factory()->post->create_and_get( array(106 'post_title' => 'First',107 'post_date' => '2012-01-01 12:00:00'108 ) );109 110 $post_two = self::factory()->post->create_and_get( array(111 'post_title' => 'Second',112 'post_date' => '2012-02-01 12:00:00'113 ) );114 115 $post_three = self::factory()->post->create_and_get( array(116 'post_title' => 'Third',117 'post_date' => '2012-03-01 12:00:00'118 ) );119 120 $post_four = self::factory()->post->create_and_get( array(121 'post_title' => 'Fourth',122 'post_date' => '2012-04-01 12:00:00'123 ) );124 125 // Assign some terms126 wp_set_object_terms( $post_one->ID, 'wordpress', 'category', false );127 wp_set_object_terms( $post_three->ID, 'wordpress', 'category', false );128 129 wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false );130 wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false );131 132 // Test normal post adjacency133 $this->go_to( get_permalink( $post_two->ID ) );134 135 $this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );136 $this->assertEquals( $post_three, get_adjacent_post( false, '', false ) );137 138 $this->assertNotEquals( $post_two, get_adjacent_post( false, '', true ) );139 $this->assertNotEquals( $post_two, get_adjacent_post( false, '', false ) );140 141 // Test category adjacency142 $this->go_to( get_permalink( $post_one->ID ) );143 144 $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) );145 $this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) );146 147 // Test tag adjacency148 $this->go_to( get_permalink( $post_two->ID ) );149 150 $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) );151 $this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) );152 153 // Test normal boundary post154 $this->go_to( get_permalink( $post_two->ID ) );155 156 $this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) );157 $this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) );158 159 // Test category boundary post160 $this->go_to( get_permalink( $post_one->ID ) );161 162 $this->assertEquals( array( $post_one ), get_boundary_post( true, '', true, 'category' ) );163 $this->assertEquals( array( $post_three ), get_boundary_post( true, '', false, 'category' ) );164 165 // Test tag boundary post166 $this->go_to( get_permalink( $post_two->ID ) );167 168 $this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );169 $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );170 }171 172 /**173 * @ticket 22112174 */175 function test_get_adjacent_post_exclude_self_term() {176 // Bump term_taxonomy to mimic shared term offsets.177 global $wpdb;178 $wpdb->insert( $wpdb->term_taxonomy, array( 'taxonomy' => 'foo', 'term_id' => 12345, 'description' => '' ) );179 180 $include = self::factory()->term->create( array(181 'taxonomy' => 'category',182 'name' => 'Include',183 ) );184 $exclude = self::factory()->category->create();185 186 $one = self::factory()->post->create_and_get( array(187 'post_date' => '2012-01-01 12:00:00',188 'post_category' => array( $include, $exclude ),189 ) );190 191 $two = self::factory()->post->create_and_get( array(192 'post_date' => '2012-01-02 12:00:00',193 'post_category' => array(),194 ) );195 196 $three = self::factory()->post->create_and_get( array(197 'post_date' => '2012-01-03 12:00:00',198 'post_category' => array( $include, $exclude ),199 ) );200 201 $four = self::factory()->post->create_and_get( array(202 'post_date' => '2012-01-04 12:00:00',203 'post_category' => array( $include ),204 ) );205 206 $five = self::factory()->post->create_and_get( array(207 'post_date' => '2012-01-05 12:00:00',208 'post_category' => array( $include, $exclude ),209 ) );210 211 // First post212 $this->go_to( get_permalink( $one ) );213 $this->assertEquals( $two, get_adjacent_post( false, array(), false ) );214 $this->assertEquals( $three, get_adjacent_post( true, array(), false ) );215 $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), false ) );216 $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), false ) );217 $this->assertEmpty( get_adjacent_post( false, array(), true ) );218 219 // Fourth post220 $this->go_to( get_permalink( $four ) );221 $this->assertEquals( $five, get_adjacent_post( false, array(), false ) );222 $this->assertEquals( $five, get_adjacent_post( true, array(), false ) );223 $this->assertEmpty( get_adjacent_post( false, array( $exclude ), false ) );224 $this->assertEmpty( get_adjacent_post( true, array( $exclude ), false ) );225 226 $this->assertEquals( $three, get_adjacent_post( false, array(), true ) );227 $this->assertEquals( $three, get_adjacent_post( true, array(), true ) );228 $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), true ) );229 $this->assertEmpty( get_adjacent_post( true, array( $exclude ), true ) );230 231 // Last post232 $this->go_to( get_permalink( $five ) );233 $this->assertEquals( $four, get_adjacent_post( false, array(), true ) );234 $this->assertEquals( $four, get_adjacent_post( true, array(), true ) );235 $this->assertEquals( $four, get_adjacent_post( false, array( $exclude ), true ) );236 $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), true ) );237 $this->assertEmpty( get_adjacent_post( false, array(), false ) );238 }239 240 /**241 * @ticket 32833242 */243 public function test_get_adjacent_post_excluded_terms() {244 register_taxonomy( 'wptests_tax', 'post' );245 246 $t = self::factory()->term->create( array(247 'taxonomy' => 'wptests_tax',248 ) );249 250 $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );251 $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );252 $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );253 254 wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );255 256 // Fake current page.257 $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;258 $GLOBALS['post'] = get_post( $p1 );259 260 $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );261 262 if ( ! is_null( $_post ) ) {263 $GLOBALS['post'] = $_post;264 } else {265 unset( $GLOBALS['post'] );266 }267 268 // Should skip $p2, which belongs to $t.269 $this->assertEquals( $p3, $found->ID );270 }271 272 /**273 * @ticket 32833274 */275 public function test_get_adjacent_post_excluded_terms_should_not_require_posts_to_have_terms_in_any_taxonomy() {276 register_taxonomy( 'wptests_tax', 'post' );277 278 $t = self::factory()->term->create( array(279 'taxonomy' => 'wptests_tax',280 ) );281 282 $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );283 $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );284 $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );285 286 wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );287 288 // Make sure that $p3 doesn't have the 'Uncategorized' category.289 wp_delete_object_term_relationships( $p3, 'category' );290 291 // Fake current page.292 $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;293 $GLOBALS['post'] = get_post( $p1 );294 295 $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );296 297 if ( ! is_null( $_post ) ) {298 $GLOBALS['post'] = $_post;299 } else {300 unset( $GLOBALS['post'] );301 }302 303 // Should skip $p2, which belongs to $t.304 $this->assertEquals( $p3, $found->ID );305 }306 307 /**308 101 * @ticket 30910 309 102 */ -
trunk/tests/phpunit/tests/link/getAdjacentPost.php
r36076 r36077 2 2 /** 3 3 * @group link 4 * @covers ::get_adjacent_link 4 5 */ 5 class Tests_Link extends WP_UnitTestCase { 6 7 function _get_pagenum_link_cb( $url ) { 8 return $url . '/WooHoo'; 9 } 10 11 /** 12 * @ticket 8847 13 */ 14 function test_get_pagenum_link_case_insensitivity() { 15 $old_req_uri = $_SERVER['REQUEST_URI']; 16 17 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 18 19 add_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) ); 20 $_SERVER['REQUEST_URI'] = '/woohoo'; 21 $paged = get_pagenum_link( 2 ); 22 23 remove_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) ); 24 $this->assertEquals( $paged, home_url( '/WooHoo/page/2/' ) ); 25 26 $_SERVER['REQUEST_URI'] = $old_req_uri; 27 } 28 29 function test_wp_get_shortlink() { 30 $post_id = self::factory()->post->create(); 31 $post_id2 = self::factory()->post->create(); 32 33 // Basic case 34 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 35 36 unset( $GLOBALS['post'] ); 37 38 // Global post is not set 39 $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); 40 $this->assertEquals( '', wp_get_shortlink( 0 ) ); 41 $this->assertEquals( '', wp_get_shortlink() ); 42 43 $GLOBALS['post'] = get_post( $post_id ); 44 45 // Global post is set 46 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) ); 47 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) ); 48 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() ); 49 50 // Not the global post 51 $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) ); 52 53 unset( $GLOBALS['post'] ); 54 55 // Global post is not set, once again 56 $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); 57 $this->assertEquals( '', wp_get_shortlink( 0 ) ); 58 $this->assertEquals( '', wp_get_shortlink() ); 59 60 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 61 62 // With a permalink structure set, get_permalink() will no longer match. 63 $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 64 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 65 66 // Global post and permalink structure are set 67 $GLOBALS['post'] = get_post( $post_id ); 68 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) ); 69 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); 70 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() ); 71 } 72 73 function test_wp_get_shortlink_with_page() { 74 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 75 76 // Basic case 77 // Don't test against get_permalink() since it uses ?page_id= for pages. 78 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 79 80 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 81 82 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 83 } 84 85 /** 86 * @ticket 26871 87 */ 88 function test_wp_get_shortlink_with_home_page() { 89 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 90 update_option( 'show_on_front', 'page' ); 91 update_option( 'page_on_front', $post_id ); 92 93 $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) ); 94 95 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 96 97 $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) ); 98 } 99 6 class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { 100 7 /** 101 8 * @ticket 17807 102 9 */ 103 function test_get_adjacent_post() {10 public function test_get_adjacent_post() { 104 11 // Need some sample posts to test adjacency 105 12 $post_one = self::factory()->post->create_and_get( array( … … 304 211 $this->assertEquals( $p3, $found->ID ); 305 212 } 306 307 /**308 * @ticket 30910309 */310 public function test_get_permalink_should_not_reveal_post_name_for_post_with_post_status_future() {311 update_option( 'permalink_structure','/%year%/%monthnum%/%day%/%postname%/' );312 313 flush_rewrite_rules();314 315 $p = self::factory()->post->create( array(316 'post_status' => 'publish',317 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', strtotime( '+1 day' ) )318 ) );319 320 $non_pretty_permalink = add_query_arg( 'p', $p, trailingslashit( home_url() ) );321 322 $this->assertEquals( $non_pretty_permalink, get_permalink( $p ) );323 }324 325 /**326 * @ticket 30910327 */328 public function test_get_permalink_should_not_reveal_post_name_for_cpt_with_post_status_future() {329 update_option( 'permalink_structure','/%year%/%monthnum%/%day%/%postname%/' );330 331 register_post_type( 'wptests_pt', array( 'public' => true ) );332 333 flush_rewrite_rules();334 335 $p = self::factory()->post->create( array(336 'post_status' => 'future',337 'post_type' => 'wptests_pt',338 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', strtotime( '+1 day' ) )339 ) );340 341 $non_pretty_permalink = add_query_arg( array(342 'post_type' => 'wptests_pt',343 'p' => $p,344 ), trailingslashit( home_url() ) );345 346 $this->assertEquals( $non_pretty_permalink, get_permalink( $p ) );347 }348 349 /**350 * @ticket 1914351 */352 public function test_unattached_attachment_has_a_pretty_permalink() {353 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );354 355 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', 0, array(356 'post_mime_type' => 'image/jpeg',357 'post_type' => 'attachment',358 'post_title' => 'An Attachment!',359 'post_status' => 'inherit',360 ) );361 362 $attachment = get_post( $attachment_id );363 364 $this->assertSame( home_url( user_trailingslashit( $attachment->post_name ) ), get_permalink( $attachment_id ) );365 }366 367 /**368 * @ticket 1914369 */370 public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() {371 global $wp_post_types;372 373 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );374 375 register_post_type( 'not_a_post_type', array( 'public' => true ) );376 377 flush_rewrite_rules();378 379 $post_id = self::factory()->post->create( array( 'post_type' => 'not_a_post_type' ) );380 381 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array(382 'post_mime_type' => 'image/jpeg',383 'post_type' => 'attachment',384 'post_title' => 'An Attachment!',385 'post_status' => 'inherit',386 ) );387 388 $attachment = get_post( $attachment_id );389 390 $this->assertSame( get_permalink( $post_id ) . user_trailingslashit( $attachment->post_name ), get_permalink( $attachment_id ) );391 392 foreach( $wp_post_types as $id => $pt ) {393 if ( 'not_a_post_type' === $pt->name ) {394 unset( $wp_post_types[ $id ] );395 break;396 }397 }398 399 $this->assertSame( home_url( user_trailingslashit( $attachment->post_name ) ), get_permalink( $attachment_id ) );400 }401 213 }
Note: See TracChangeset
for help on using the changeset viewer.