Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/phpunit/tests/link/getAdjacentPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function test_get_adjacent_post() {
// Test normal post adjacency.
$this->go_to( get_permalink( $post_two->ID ) );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );
$this->assertEquals( $post_three, get_adjacent_post( false, '', false ) );

Expand All @@ -59,29 +60,34 @@ public function test_get_adjacent_post() {
$this->go_to( get_permalink( $post_one->ID ) );

$this->assertSame( '', get_adjacent_post( true, '', true, 'category' ) );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) );

// Test tag adjacency.
$this->go_to( get_permalink( $post_two->ID ) );

$this->assertSame( '', get_adjacent_post( true, '', true, 'post_tag' ) );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) );

// Test normal boundary post.
$this->go_to( get_permalink( $post_two->ID ) );

// Keep assertEquals() because the array of objects are intentionally compared by value.
$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 ) );

// Keep assertEquals() because the array of objects are intentionally compared by value.
$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 ) );

// Keep assertEquals() because the array of objects are intentionally compared by value.
$this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );
$this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
}
Expand Down Expand Up @@ -146,6 +152,7 @@ public function test_get_adjacent_post_exclude_self_term() {

// First post.
$this->go_to( get_permalink( $one ) );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $two, get_adjacent_post( false, array(), false ) );
$this->assertEquals( $three, get_adjacent_post( true, array(), false ) );
$this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), false ) );
Expand All @@ -154,18 +161,21 @@ public function test_get_adjacent_post_exclude_self_term() {

// Fourth post.
$this->go_to( get_permalink( $four ) );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $five, get_adjacent_post( false, array(), false ) );
$this->assertEquals( $five, get_adjacent_post( true, array(), false ) );
$this->assertEmpty( get_adjacent_post( false, array( $exclude ), false ) );
$this->assertEmpty( get_adjacent_post( true, array( $exclude ), false ) );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $three, get_adjacent_post( false, array(), true ) );
$this->assertEquals( $three, get_adjacent_post( true, array(), true ) );
$this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), true ) );
$this->assertEmpty( get_adjacent_post( true, array( $exclude ), true ) );

// Last post.
$this->go_to( get_permalink( $five ) );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $four, get_adjacent_post( false, array(), true ) );
$this->assertEquals( $four, get_adjacent_post( true, array(), true ) );
$this->assertEquals( $four, get_adjacent_post( false, array( $exclude ), true ) );
Expand Down Expand Up @@ -555,13 +565,15 @@ public function test_get_adjacent_post_cache() {

// Test getting the right result.
$first_run = get_adjacent_post( false, '', true );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_one, $first_run, 'Did not get first post when on second post' );
$this->assertNotEquals( $post_two, $first_run, 'Got second post when on second post' );

// Query count to test caching.
$num_queries = get_num_queries();
$second_run = get_adjacent_post( false, '', true );
$this->assertNotEquals( $post_two, $second_run, 'Got second post when on second post on second run' );
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_one, $second_run, 'Did not get first post when on second post on second run' );
$this->assertSame( $num_queries, get_num_queries() );

Expand All @@ -574,16 +586,20 @@ public function test_get_adjacent_post_cache() {
);
$num_queries = get_num_queries();

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_one, get_adjacent_post( false, '', true ), 'Did not get first post after new post is added' );
$this->assertSame( get_num_queries() - $num_queries, 1, 'Number of queries run was not one after new post is added' );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Did not get forth post after new post is added' );
$num_queries = get_num_queries();
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Did not get forth post after new post is added' );
$this->assertSame( $num_queries, get_num_queries() );
wp_set_object_terms( $post_four->ID, 'themes', 'post_tag', false );

$num_queries = get_num_queries();
// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Result of function call is wrong after after adding new term' );
$this->assertSame( get_num_queries() - $num_queries, 2, 'Number of queries run was not two after adding new term' );
}
Expand Down
Loading