Make WordPress Core


Ignore:
Timestamp:
03/29/2014 06:02:01 AM (12 years ago)
Author:
nacin
Message:

Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.

Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].

see #26937.

File:
1 edited

Legend:

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

    r27803 r27836  
    189189        $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
    190190    }
    191 
    192     /**
    193      * @ticket 26937
    194      */
    195     function test_legacy_get_adjacent_post_filters() {
    196         // Need some sample posts to test adjacency
    197         $post_one = $this->factory->post->create_and_get( array(
    198             'post_title' => 'First',
    199             'post_date'  => '2012-01-01 12:00:00',
    200         ) );
    201 
    202         $post_two = $this->factory->post->create_and_get( array(
    203             'post_title' => 'Second',
    204             'post_date'  => '2012-02-01 12:00:00',
    205         ) );
    206 
    207         $post_three = $this->factory->post->create_and_get( array(
    208             'post_title' => 'Third',
    209             'post_date'  => '2012-03-01 12:00:00',
    210         ) );
    211 
    212         $post_four = $this->factory->post->create_and_get( array(
    213             'post_title' => 'Fourth',
    214             'post_date'  => '2012-04-01 12:00:00',
    215         ) );
    216 
    217         // Use pages to test post-type adjacency
    218         $page_one = $this->factory->post->create_and_get( array(
    219             'post_title' => 'First Page',
    220             'post_date'  => '2013-01-01 12:00:00',
    221             'post_type'  => 'page',
    222         ) );
    223 
    224         $page_two = $this->factory->post->create_and_get( array(
    225             'post_title' => 'Second Page',
    226             'post_date'  => '2013-02-01 12:00:00',
    227             'post_type'  => 'page',
    228         ) );
    229 
    230         // Add some meta so we can join the postmeta table and query
    231         add_post_meta( $post_three->ID, 'unit_test_meta', 'waffle' );
    232 
    233         // Test "where" filter for a previous post
    234         add_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );
    235         $this->go_to( get_permalink( $post_three->ID ) );
    236         $this->assertEquals( $post_one, get_adjacent_post( false, null, true ) );
    237         remove_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );
    238 
    239         // Test "where" filter for a next post
    240         add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );
    241         $this->go_to( get_permalink( $post_two->ID ) );
    242         $this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );
    243         remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );
    244 
    245         // Test "where" filter that writes its own query
    246         add_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );
    247         $this->go_to( get_permalink( $post_four->ID ) );
    248         $this->assertEquals( $post_two, get_adjacent_post( false, null, true ) );
    249         remove_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );
    250 
    251         // Test "join" filter by joining the postmeta table and restricting by meta key
    252         add_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );
    253         add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );
    254         $this->go_to( get_permalink( $post_one->ID ) );
    255         $this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
    256         remove_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );
    257         remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );
    258 
    259         // Test "sort" filter when modifying ORDER BY clause
    260         add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );
    261         $this->go_to( get_permalink( $post_one->ID ) );
    262         $this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );
    263         remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );
    264 
    265         // Test "sort" filter when modifying LIMIT clause
    266         add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );
    267         $this->go_to( get_permalink( $post_one->ID ) );
    268         $this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
    269         remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );
    270 
    271         // Test post-type specificity
    272         $this->go_to( get_permalink( $page_one ) );
    273         $this->assertEquals( $page_two, get_adjacent_post( false, null, false ) );
    274 
    275         $this->go_to( get_permalink( $page_two ) );
    276         $this->assertEquals( $page_one, get_adjacent_post( false, null, true ) );
    277     }
    278 
    279     /**
    280      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    281      */
    282     function filter_previous_post_where( $where ) {
    283         $where .= " AND post_title !='Second'";
    284         return $where;
    285     }
    286 
    287     /**
    288      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    289      */
    290     function filter_next_post_where( $where ) {
    291         $where .= " AND post_title !='Third'";
    292         return $where;
    293     }
    294 
    295     /**
    296      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    297      */
    298     function override_previous_post_where_clause( $where ) {
    299         $where = "WHERE p.post_date < '2012-02-28'";
    300         return $where;
    301     }
    302 
    303     /**
    304      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    305      */
    306     function filter_next_post_join( $join ) {
    307         global $wpdb;
    308 
    309         $join .= " INNER JOIN {$wpdb->postmeta} ON p.ID = {$wpdb->postmeta}.post_id";
    310         return $join;
    311     }
    312 
    313     /**
    314      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    315      */
    316     function filter_next_post_where_with_join( $where ) {
    317         global $wpdb;
    318 
    319         $where .= " AND {$wpdb->postmeta}.meta_key = 'unit_test_meta'";
    320         return $where;
    321     }
    322 
    323     /**
    324      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    325      */
    326     function filter_next_post_sort( $sort ) {
    327         return str_replace( 'p.post_date', 'p.post_title', $sort );
    328     }
    329 
    330     /**
    331      * Filter callback for `test_legacy_get_adjacent_post_filters()`
    332      */
    333     function filter_next_post_sort_limit( $sort ) {
    334         $sort = str_replace( 'LIMIT 0, 1', 'LIMIT 1, 2', $sort );
    335         return $sort;
    336     }
    337191}
Note: See TracChangeset for help on using the changeset viewer.