Make WordPress Core

Ticket #21309: 21309-get_adjacent_post-ut.diff

File 21309-get_adjacent_post-ut.diff, 1.2 KB (added by ryan, 13 years ago)
  • tests/url.php

     
    156156                force_ssl_admin( $forced_admin );
    157157                force_ssl_login( $forced_login );
    158158        }
     159
     160        function test_get_adjacent_post() {
     161                $post_id = $this->factory->post->create();
     162                sleep( 1 ); // get_adjacent_post() doesn't handle posts created in the same second.
     163                $post_id2 = $this->factory->post->create();
     164
     165                $orig_post = $GLOBALS['post'];
     166                $GLOBALS['post'] = get_post( $post_id2 );
     167
     168                $p = get_adjacent_post();
     169                $this->assertInstanceOf( 'WP_Post', $p );
     170                $this->assertEquals( $post_id, $p->ID );
     171
     172                // The same again to make sure a cached query returns the same result
     173                $p = get_adjacent_post();
     174                $this->assertInstanceOf( 'WP_Post', $p );
     175                $this->assertEquals( $post_id, $p->ID );
     176
     177                // Test next
     178                $p = get_adjacent_post( false, '', false );
     179                $this->assertEquals( '', $p );
     180
     181                unset( $GLOBALS['post'] );
     182                $this->assertNull( get_adjacent_post() );
     183
     184                $GLOBALS['post'] = $orig_post;
     185
     186                // Tests requiring creating more posts can't be run since the query
     187                // cache in get_adjacent_post() requires a fresh page load to invalidate.
     188        }
    159189}