| 99 | /** |
| 100 | * @ticket 17807 |
| 101 | */ |
| 102 | function test_get_adjacent_post() { |
| 103 | // Need some sample posts to test adjacency |
| 104 | $post_one = $this->factory->post->create( array( |
| 105 | 'post_title' => 'First', |
| 106 | 'post_date' => '2012-01-01 12:00:00' |
| 107 | ) ); |
| 108 | |
| 109 | $post_two = $this->factory->post->create( array( |
| 110 | 'post_title' => 'Second', |
| 111 | 'post_date' => '2012-02-01 12:00:00' |
| 112 | ) ); |
| 113 | |
| 114 | $post_three = $this->factory->post->create( array( |
| 115 | 'post_title' => 'Third', |
| 116 | 'post_date' => '2012-03-01 12:00:00' |
| 117 | ) ); |
| 118 | |
| 119 | $post_four = $this->factory->post->create( array( |
| 120 | 'post_title' => 'Fourth', |
| 121 | 'post_date' => '2012-04-01 12:00:00' |
| 122 | ) ); |
| 123 | |
| 124 | // Assign some terms |
| 125 | wp_set_object_terms( $post_one, 'wordpress', 'category', false ); |
| 126 | wp_set_object_terms( $post_three, 'wordpress', 'category', false ); |
| 127 | |
| 128 | wp_set_object_terms( $post_two, 'plugins', 'post_tag', false ); |
| 129 | wp_set_object_terms( $post_four, 'plugins', 'post_tag', false ); |
| 130 | |
| 131 | // Test normal post adjacency |
| 132 | $this->go_to( get_permalink( $post_two ) ); |
| 133 | |
| 134 | $this->assertEquals( get_post( $post_one ), get_adjacent_post( false, '', true ) ); |
| 135 | $this->assertEquals( get_post( $post_three ), get_adjacent_post( false, '', false ) ); |
| 136 | |
| 137 | $this->assertNotEquals( get_post( $post_two ), get_adjacent_post( false, '', true ) ); |
| 138 | $this->assertNotEquals( get_post( $post_two ), get_adjacent_post( false, '', false ) ); |
| 139 | |
| 140 | // Test category adjacency |
| 141 | $this->go_to( get_permalink( $post_one ) ); |
| 142 | |
| 143 | $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) ); |
| 144 | $this->assertEquals( get_post( $post_three ), get_adjacent_post( true, '', false, 'category' ) ); |
| 145 | |
| 146 | // Test tag adjacency |
| 147 | $this->go_to( get_permalink( $post_two ) ); |
| 148 | |
| 149 | $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) ); |
| 150 | $this->assertEquals( get_post( $post_four ), get_adjacent_post( true, '', false, 'post_tag' ) ); |
| 151 | |
| 152 | // Test normal boundary post |
| 153 | $this->go_to( get_permalink( $post_two ) ); |
| 154 | |
| 155 | $this->assertEquals( get_posts( array( 'p' => $post_one ) ), get_boundary_post( false, '', true ) ); |
| 156 | $this->assertEquals( get_posts( array( 'p' => $post_four ) ), get_boundary_post( false, '', false ) ); |
| 157 | |
| 158 | // Test category boundary post |
| 159 | $this->go_to( get_permalink( $post_one ) ); |
| 160 | |
| 161 | $this->assertEquals( get_posts( array( 'p' => $post_one ) ), get_boundary_post( true, '', true, 'category' ) ); |
| 162 | $this->assertEquals( get_posts( array( 'p' => $post_three ) ), get_boundary_post( true, '', false, 'category' ) ); |
| 163 | |
| 164 | // Test tag boundary post |
| 165 | $this->go_to( get_permalink( $post_two ) ); |
| 166 | |
| 167 | $this->assertEquals( get_posts( array( 'p' => $post_two ) ), get_boundary_post( true, '', true, 'post_tag' ) ); |
| 168 | $this->assertEquals( get_post( array( 'p' => $post_four ) ), get_boundary_post( true, '', false, 'post_tag' ) ); |
| 169 | } |