| 30 | |
| 31 | /** |
| 32 | * @ticket 17807 |
| 33 | */ |
| 34 | function test_get_adjacent_post() { |
| 35 | // Need some sample posts to test adjacency |
| 36 | $post_one = $this->factory->post->create( array( |
| 37 | 'post_title' => 'First', |
| 38 | 'post_date' => '2012-01-01 12:00:00' |
| 39 | ) ); |
| 40 | |
| 41 | $post_two = $this->factory->post->create( array( |
| 42 | 'post_title' => 'Second', |
| 43 | 'post_date' => '2012-02-01 12:00:00' |
| 44 | ) ); |
| 45 | |
| 46 | $post_three = $this->factory->post->create( array( |
| 47 | 'post_title' => 'Third', |
| 48 | 'post_date' => '2012-03-01 12:00:00' |
| 49 | ) ); |
| 50 | |
| 51 | $post_four = $this->factory->post->create( array( |
| 52 | 'post_title' => 'Fourth', |
| 53 | 'post_date' => '2012-04-01 12:00:00' |
| 54 | ) ); |
| 55 | |
| 56 | // Assign some terms |
| 57 | wp_set_object_terms( $post_one, 'wordpress', 'category', false ); |
| 58 | wp_set_object_terms( $post_three, 'wordpress', 'category', false ); |
| 59 | |
| 60 | wp_set_object_terms( $post_two, 'plugins', 'post_tag', false ); |
| 61 | wp_set_object_terms( $post_four, 'plugins', 'post_tag', false ); |
| 62 | |
| 63 | // Test normal post adjacency |
| 64 | $this->go_to( get_permalink( $post_two ) ); |
| 65 | |
| 66 | $this->assertEquals( get_post( $post_one ), get_adjacent_post( false, '', true ) ); |
| 67 | $this->assertEquals( get_post( $post_three ), get_adjacent_post( false, '', false ) ); |
| 68 | |
| 69 | $this->assertNotEquals( get_post( $post_two ), get_adjacent_post( false, '', true ) ); |
| 70 | $this->assertNotEquals( get_post( $post_two ), get_adjacent_post( false, '', false ) ); |
| 71 | |
| 72 | // Test category adjacency |
| 73 | $this->go_to( get_permalink( $post_one ) ); |
| 74 | |
| 75 | $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) ); |
| 76 | $this->assertEquals( get_post( $post_three ), get_adjacent_post( true, '', false, 'category' ) ); |
| 77 | |
| 78 | // Test tag adjacency |
| 79 | $this->go_to( get_permalink( $post_two ) ); |
| 80 | |
| 81 | $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) ); |
| 82 | $this->assertEquals( get_post( $post_four ), get_adjacent_post( true, '', false, 'post_tag' ) ); |
| 83 | |
| 84 | // Test normal boundary post |
| 85 | $this->go_to( get_permalink( $post_two ) ); |
| 86 | |
| 87 | $this->assertEquals( get_posts( array( 'p' => $post_one ) ), get_boundary_post( false, '', true ) ); |
| 88 | $this->assertEquals( get_posts( array( 'p' => $post_four ) ), get_boundary_post( false, '', false ) ); |
| 89 | |
| 90 | // Test category boundary post |
| 91 | $this->go_to( get_permalink( $post_one ) ); |
| 92 | |
| 93 | $this->assertEquals( get_posts( array( 'p' => $post_one ) ), get_boundary_post( true, '', true, 'category' ) ); |
| 94 | $this->assertEquals( get_posts( array( 'p' => $post_three ) ), get_boundary_post( true, '', false, 'category' ) ); |
| 95 | |
| 96 | // Test tag boundary post |
| 97 | $this->go_to( get_permalink( $post_two ) ); |
| 98 | |
| 99 | $this->assertEquals( get_posts( array( 'p' => $post_two ) ), get_boundary_post( true, '', true, 'post_tag' ) ); |
| 100 | $this->assertEquals( get_post( array( 'p' => $post_four ) ), get_boundary_post( true, '', false, 'post_tag' ) ); |
| 101 | } |