WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/23/2015 07:56:32 PM (4 years ago)
Author:
boonebgorges
Message:

Move excluded_terms filter in get_adjacent_post().

The filter was added in 4.4 [34528] #9571, but in a place where it could not
affect the adjacent post query.

Fixes #35211.

File:
1 edited

Legend:

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

    r36077 r36078  
    55 */
    66class Tests_Link_GetAdjacentPost extends WP_UnitTestCase {
     7    protected $exclude_term;
     8
    79    /**
    810     * @ticket 17807
     
    211213        $this->assertEquals( $p3, $found->ID );
    212214    }
     215
     216    /**
     217     * @ticket 35211
     218     */
     219    public function test_excluded_terms_filter() {
     220        register_taxonomy( 'wptests_tax', 'post' );
     221
     222        $terms = self::factory()->term->create_many( 2, array(
     223            'taxonomy' => 'wptests_tax',
     224        ) );
     225
     226        $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     227        $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     228        $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     229
     230        wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' );
     231        wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' );
     232        wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' );
     233
     234        $this->go_to( get_permalink( $p1 ) );
     235
     236        $this->exclude_term = $terms[1];
     237        add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     238
     239        $found = get_adjacent_post( true, array(), true, 'wptests_tax' );
     240
     241        remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     242        unset( $this->exclude_term );
     243
     244        $this->assertSame( $p3, $found->ID );
     245    }
     246
     247    public function filter_excluded_terms( $excluded_terms ) {
     248        $excluded_terms[] = $this->exclude_term;
     249        return $excluded_terms;
     250    }
    213251}
Note: See TracChangeset for help on using the changeset viewer.