mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument. Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link(). props ethitter. finally fixes #17807. git-svn-id: https://develop.svn.wordpress.org/trunk@25959 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -96,4 +96,75 @@ class Tests_Link extends WP_UnitTestCase {
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 17807
|
||||
*/
|
||||
function test_get_adjacent_post() {
|
||||
// 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'
|
||||
) );
|
||||
|
||||
// Assign some terms
|
||||
wp_set_object_terms( $post_one->ID, 'wordpress', 'category', false );
|
||||
wp_set_object_terms( $post_three->ID, 'wordpress', 'category', false );
|
||||
|
||||
wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false );
|
||||
wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false );
|
||||
|
||||
// Test normal post adjacency
|
||||
$this->go_to( get_permalink( $post_two->ID ) );
|
||||
|
||||
$this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );
|
||||
$this->assertEquals( $post_three, get_adjacent_post( false, '', false ) );
|
||||
|
||||
$this->assertNotEquals( $post_two, get_adjacent_post( false, '', true ) );
|
||||
$this->assertNotEquals( $post_two, get_adjacent_post( false, '', false ) );
|
||||
|
||||
// Test category adjacency
|
||||
$this->go_to( get_permalink( $post_one->ID ) );
|
||||
|
||||
$this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) );
|
||||
$this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) );
|
||||
|
||||
// Test tag adjacency
|
||||
$this->go_to( get_permalink( $post_two->ID ) );
|
||||
|
||||
$this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) );
|
||||
$this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) );
|
||||
|
||||
// Test normal boundary post
|
||||
$this->go_to( get_permalink( $post_two->ID ) );
|
||||
|
||||
$this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) );
|
||||
$this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) );
|
||||
|
||||
// Test category boundary post
|
||||
$this->go_to( get_permalink( $post_one->ID ) );
|
||||
|
||||
$this->assertEquals( array( $post_one ), get_boundary_post( true, '', true, 'category' ) );
|
||||
$this->assertEquals( array( $post_three ), get_boundary_post( true, '', false, 'category' ) );
|
||||
|
||||
// Test tag boundary post
|
||||
$this->go_to( get_permalink( $post_two->ID ) );
|
||||
|
||||
$this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );
|
||||
$this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user