Make WordPress Core


Ignore:
Timestamp:
09/12/2015 08:33:07 PM (11 years ago)
Author:
boonebgorges
Message:

Remove extraneous table join in get_adjacent_post().

Since [29248], a table join has not been necessary to process the
$excluded_terms parameter of get_adjacent_post(). Aside from adding extra
overhead, this join meant that post records that don't have any corresponding
rows in wp_term_relationships were erroneously excluded from results.

Fixes #32833.

File:
1 edited

Legend:

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

    r31622 r34088  
    258258        }
    259259
     260        /**
     261         * @ticket 32833
     262         */
     263        public function test_get_adjacent_post_excluded_terms() {
     264                register_taxonomy( 'wptests_tax', 'post' );
     265
     266                $t = $this->factory->term->create( array(
     267                        'taxonomy' => 'wptests_tax',
     268                ) );
     269
     270                $p1 = $this->factory->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     271                $p2 = $this->factory->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     272                $p3 = $this->factory->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     273
     274                wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );
     275
     276                // Fake current page.
     277                $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     278                $GLOBALS['post'] = get_post( $p1 );
     279
     280                $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );
     281
     282                if ( ! is_null( $_post ) ) {
     283                        $GLOBALS['post'] = $_post;
     284                } else {
     285                        unset( $GLOBALS['post'] );
     286                }
     287
     288                // Should skip $p2, which belongs to $t.
     289                $this->assertEquals( $p3, $found->ID );
     290        }
     291
     292        /**
     293         * @ticket 32833
     294         */
     295        public function test_get_adjacent_post_excluded_terms_should_not_require_posts_to_have_terms_in_any_taxonomy() {
     296                register_taxonomy( 'wptests_tax', 'post' );
     297
     298                $t = $this->factory->term->create( array(
     299                        'taxonomy' => 'wptests_tax',
     300                ) );
     301
     302                $p1 = $this->factory->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     303                $p2 = $this->factory->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     304                $p3 = $this->factory->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     305
     306                wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );
     307
     308                // Make sure that $p3 doesn't have the 'Uncategorized' category.
     309                wp_delete_object_term_relationships( $p3, 'category' );
     310
     311                // Fake current page.
     312                $_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     313                $GLOBALS['post'] = get_post( $p1 );
     314
     315                $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );
     316
     317                if ( ! is_null( $_post ) ) {
     318                        $GLOBALS['post'] = $_post;
     319                } else {
     320                        unset( $GLOBALS['post'] );
     321                }
     322
     323                // Should skip $p2, which belongs to $t.
     324                $this->assertEquals( $p3, $found->ID );
     325        }
     326
    260327        public function test_wp_make_link_relative_with_http_scheme() {
    261328                $link = 'http://example.com/this-is-a-test-http-url/';
Note: See TracChangeset for help on using the changeset viewer.