mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@27836 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -188,150 +188,4 @@ class Tests_Link extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );
|
||||
$this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 26937
|
||||
*/
|
||||
function test_legacy_get_adjacent_post_filters() {
|
||||
// Need some sample posts to test adjacency
|
||||
$post_one = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'First',
|
||||
'post_date' => '2012-01-01 12:00:00',
|
||||
) );
|
||||
|
||||
$post_two = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Second',
|
||||
'post_date' => '2012-02-01 12:00:00',
|
||||
) );
|
||||
|
||||
$post_three = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Third',
|
||||
'post_date' => '2012-03-01 12:00:00',
|
||||
) );
|
||||
|
||||
$post_four = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Fourth',
|
||||
'post_date' => '2012-04-01 12:00:00',
|
||||
) );
|
||||
|
||||
// Use pages to test post-type adjacency
|
||||
$page_one = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'First Page',
|
||||
'post_date' => '2013-01-01 12:00:00',
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
$page_two = $this->factory->post->create_and_get( array(
|
||||
'post_title' => 'Second Page',
|
||||
'post_date' => '2013-02-01 12:00:00',
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
// Add some meta so we can join the postmeta table and query
|
||||
add_post_meta( $post_three->ID, 'unit_test_meta', 'waffle' );
|
||||
|
||||
// Test "where" filter for a previous post
|
||||
add_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );
|
||||
$this->go_to( get_permalink( $post_three->ID ) );
|
||||
$this->assertEquals( $post_one, get_adjacent_post( false, null, true ) );
|
||||
remove_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );
|
||||
|
||||
// Test "where" filter for a next post
|
||||
add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );
|
||||
$this->go_to( get_permalink( $post_two->ID ) );
|
||||
$this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );
|
||||
remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );
|
||||
|
||||
// Test "where" filter that writes its own query
|
||||
add_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );
|
||||
$this->go_to( get_permalink( $post_four->ID ) );
|
||||
$this->assertEquals( $post_two, get_adjacent_post( false, null, true ) );
|
||||
remove_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );
|
||||
|
||||
// Test "join" filter by joining the postmeta table and restricting by meta key
|
||||
add_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );
|
||||
add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );
|
||||
$this->go_to( get_permalink( $post_one->ID ) );
|
||||
$this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
|
||||
remove_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );
|
||||
remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );
|
||||
|
||||
// Test "sort" filter when modifying ORDER BY clause
|
||||
add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );
|
||||
$this->go_to( get_permalink( $post_one->ID ) );
|
||||
$this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );
|
||||
remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );
|
||||
|
||||
// Test "sort" filter when modifying LIMIT clause
|
||||
add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );
|
||||
$this->go_to( get_permalink( $post_one->ID ) );
|
||||
$this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
|
||||
remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );
|
||||
|
||||
// Test post-type specificity
|
||||
$this->go_to( get_permalink( $page_one ) );
|
||||
$this->assertEquals( $page_two, get_adjacent_post( false, null, false ) );
|
||||
|
||||
$this->go_to( get_permalink( $page_two ) );
|
||||
$this->assertEquals( $page_one, get_adjacent_post( false, null, true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_previous_post_where( $where ) {
|
||||
$where .= " AND post_title !='Second'";
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_next_post_where( $where ) {
|
||||
$where .= " AND post_title !='Third'";
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function override_previous_post_where_clause( $where ) {
|
||||
$where = "WHERE p.post_date < '2012-02-28'";
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_next_post_join( $join ) {
|
||||
global $wpdb;
|
||||
|
||||
$join .= " INNER JOIN {$wpdb->postmeta} ON p.ID = {$wpdb->postmeta}.post_id";
|
||||
return $join;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_next_post_where_with_join( $where ) {
|
||||
global $wpdb;
|
||||
|
||||
$where .= " AND {$wpdb->postmeta}.meta_key = 'unit_test_meta'";
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_next_post_sort( $sort ) {
|
||||
return str_replace( 'p.post_date', 'p.post_title', $sort );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback for `test_legacy_get_adjacent_post_filters()`
|
||||
*/
|
||||
function filter_next_post_sort_limit( $sort ) {
|
||||
$sort = str_replace( 'LIMIT 0, 1', 'LIMIT 1, 2', $sort );
|
||||
return $sort;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user