Make WordPress Core


Ignore:
Timestamp:
12/23/2015 07:38:29 PM (11 years ago)
Author:
boonebgorges
Message:

Move get_adjacent_post() tests to their own file.

See #35211.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r36076 r36077  
    22/**
    33 * @group link
     4 * @covers ::get_adjacent_link
    45 */
    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 
     6class Tests_Link_GetAdjacentPost extends WP_UnitTestCase {
    1007        /**
    1018         * @ticket 17807
    1029         */
    103         function test_get_adjacent_post() {
     10        public function test_get_adjacent_post() {
    10411                // Need some sample posts to test adjacency
    10512                $post_one = self::factory()->post->create_and_get( array(
    … …  
    304211                $this->assertEquals( $p3, $found->ID );
    305212        }
    306 
    307         /**
    308          * @ticket 30910
    309          */
    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 30910
    327          */
    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 1914
    351          */
    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 1914
    369          */
    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         }
    401213}
Note: See TracChangeset for help on using the changeset viewer.