Make WordPress Core


Ignore:
Timestamp:
07/19/2014 10:26:43 PM (10 years ago)
Author:
wonderboymusic
Message:

In get_adjacent_post(), make $excluded_terms work as expected.

Adds unit tests.
Props jessepollak, kovshenin.
Fixes #22112.

File:
1 edited

Legend:

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

    r28966 r29248  
    189189        $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
    190190    }
     191
     192    /**
     193    * @ticket 22112
     194    */
     195    function test_get_adjacent_post_exclude_self_term() {
     196        $include = $this->factory->category->create();
     197        $exclude = $this->factory->category->create();
     198
     199        $one = $this->factory->post->create_and_get( array(
     200            'post_date' => '2012-01-01 12:00:00',
     201            'post_category' => array( $include, $exclude ),
     202        ) );
     203
     204        $two = $this->factory->post->create_and_get( array(
     205            'post_date' => '2012-01-02 12:00:00',
     206            'post_category' => array(),
     207        ) );
     208
     209        $three = $this->factory->post->create_and_get( array(
     210            'post_date' => '2012-01-03 12:00:00',
     211            'post_category' => array( $include, $exclude ),
     212        ) );
     213
     214        $four = $this->factory->post->create_and_get( array(
     215            'post_date' => '2012-01-04 12:00:00',
     216            'post_category' => array( $include ),
     217        ) );
     218
     219        $five = $this->factory->post->create_and_get( array(
     220            'post_date' => '2012-01-05 12:00:00',
     221            'post_category' => array( $include, $exclude ),
     222        ) );
     223
     224        // First post
     225        $this->go_to( get_permalink( $one ) );
     226        $this->assertEquals( $two, get_adjacent_post( false, array(), false ) );
     227        $this->assertEquals( $three, get_adjacent_post( true, array(), false ) );
     228        $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), false ) );
     229        $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), false ) );
     230        $this->assertEmpty( get_adjacent_post( false, array(), true ) );
     231
     232        // Fourth post
     233        $this->go_to( get_permalink( $four ) );
     234        $this->assertEquals( $five, get_adjacent_post( false, array(), false ) );
     235        $this->assertEquals( $five, get_adjacent_post( true, array(), false ) );
     236        $this->assertEmpty( get_adjacent_post( false, array( $exclude ), false ) );
     237        $this->assertEmpty( get_adjacent_post( true, array( $exclude ), false ) );
     238
     239        $this->assertEquals( $three, get_adjacent_post( false, array(), true ) );
     240        $this->assertEquals( $three, get_adjacent_post( true, array(), true ) );
     241        $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), true ) );
     242        $this->assertEmpty( get_adjacent_post( true, array( $exclude ), true ) );
     243
     244        // Last post
     245        $this->go_to( get_permalink( $five ) );
     246        $this->assertEquals( $four, get_adjacent_post( false, array(), true ) );
     247        $this->assertEquals( $four, get_adjacent_post( true, array(), true ) );
     248        $this->assertEquals( $four, get_adjacent_post( false, array( $exclude ), true ) );
     249        $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), true ) );
     250        $this->assertEmpty( get_adjacent_post( false, array(), false ) );
     251    }
    191252}
Note: See TracChangeset for help on using the changeset viewer.