Make WordPress Core

Ticket #27094: 27094-cpt.patch

File 27094-cpt.patch, 2.7 KB (added by tyxla, 10 years ago)

Adding support for custom post types in get_boundary_post(), including unit tests

  • src/wp-includes/link-template.php

     
    18441844                return null;
    18451845
    18461846        $query_args = array(
     1847                'post_type' => $post->post_type,
    18471848                'posts_per_page' => 1,
    18481849                'order' => $start ? 'ASC' : 'DESC',
    18491850                'update_post_term_cache' => false,
  • tests/phpunit/tests/link.php

     
    173173
    174174                $this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );
    175175                $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
     176
    176177        }
    177178
    178179        /**
     180         * @ticket 27094
     181         */
     182        function test_get_adjacent_post_custom_post_type() {
     183                // Register a sample custom post type
     184                register_post_type( 'wptests_pt', array( 'public' => true ) );
     185
     186                // Need some sample pages to test adjacency
     187                $post_one = $this->factory->post->create_and_get( array(
     188                        'post_type' => 'wptests_pt',
     189                        'post_date' => '2012-01-01 12:00:00'
     190                ) );
     191
     192                $post_two = $this->factory->post->create_and_get( array(
     193                        'post_type' => 'wptests_pt',
     194                        'post_date' => '2012-02-01 12:00:00'
     195                ) );
     196
     197                $post_three = $this->factory->post->create_and_get( array(
     198                        'post_type' => 'wptests_pt',
     199                        'post_date' => '2012-03-01 12:00:00'
     200                ) );
     201
     202                $post_four = $this->factory->post->create_and_get( array(
     203                        'post_type' => 'wptests_pt',
     204                        'post_date' => '2012-04-01 12:00:00'
     205                ) );
     206
     207                // Test normal boundary post with pages
     208                $this->go_to( get_permalink( $post_two->ID ) );
     209
     210                $this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) );
     211                $this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) );
     212        }
     213
     214        /**
     215         * @ticket 27094
     216         */
     217        function test_get_adjacent_post_attachment() {
     218
     219                // Need some sample pages to test adjacency
     220                $attachment_one = $this->factory->attachment->create_and_get( array(
     221                        'post_date' => '2012-01-01 12:00:00'
     222                ) );
     223
     224                $attachment_two = $this->factory->attachment->create_and_get( array(
     225                        'post_date' => '2012-02-01 12:00:00'
     226                ) );
     227
     228                $attachment_three = $this->factory->attachment->create_and_get( array(
     229                        'post_date' => '2012-03-01 12:00:00'
     230                ) );
     231
     232                // Test normal boundary post with pages
     233                $this->go_to( get_permalink( $attachment_two->ID ) );
     234
     235                $this->assertNull( get_boundary_post( false, '', true ) );
     236                $this->assertNull( get_boundary_post( false, '', false ) );
     237        }
     238
     239        /**
    179240         * @ticket 22112
    180241         */
    181242        function test_get_adjacent_post_exclude_self_term() {