Changeset 27836 for trunk/tests/phpunit/tests/link.php
- Timestamp:
- 03/29/2014 06:02:01 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/link.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link.php
r27803 r27836 189 189 $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) ); 190 190 } 191 192 /**193 * @ticket 26937194 */195 function test_legacy_get_adjacent_post_filters() {196 // Need some sample posts to test adjacency197 $post_one = $this->factory->post->create_and_get( array(198 'post_title' => 'First',199 'post_date' => '2012-01-01 12:00:00',200 ) );201 202 $post_two = $this->factory->post->create_and_get( array(203 'post_title' => 'Second',204 'post_date' => '2012-02-01 12:00:00',205 ) );206 207 $post_three = $this->factory->post->create_and_get( array(208 'post_title' => 'Third',209 'post_date' => '2012-03-01 12:00:00',210 ) );211 212 $post_four = $this->factory->post->create_and_get( array(213 'post_title' => 'Fourth',214 'post_date' => '2012-04-01 12:00:00',215 ) );216 217 // Use pages to test post-type adjacency218 $page_one = $this->factory->post->create_and_get( array(219 'post_title' => 'First Page',220 'post_date' => '2013-01-01 12:00:00',221 'post_type' => 'page',222 ) );223 224 $page_two = $this->factory->post->create_and_get( array(225 'post_title' => 'Second Page',226 'post_date' => '2013-02-01 12:00:00',227 'post_type' => 'page',228 ) );229 230 // Add some meta so we can join the postmeta table and query231 add_post_meta( $post_three->ID, 'unit_test_meta', 'waffle' );232 233 // Test "where" filter for a previous post234 add_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );235 $this->go_to( get_permalink( $post_three->ID ) );236 $this->assertEquals( $post_one, get_adjacent_post( false, null, true ) );237 remove_filter( 'get_previous_post_where', array( $this, 'filter_previous_post_where' ) );238 239 // Test "where" filter for a next post240 add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );241 $this->go_to( get_permalink( $post_two->ID ) );242 $this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );243 remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where' ) );244 245 // Test "where" filter that writes its own query246 add_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );247 $this->go_to( get_permalink( $post_four->ID ) );248 $this->assertEquals( $post_two, get_adjacent_post( false, null, true ) );249 remove_filter( 'get_previous_post_where', array( $this, 'override_previous_post_where_clause' ) );250 251 // Test "join" filter by joining the postmeta table and restricting by meta key252 add_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );253 add_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );254 $this->go_to( get_permalink( $post_one->ID ) );255 $this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );256 remove_filter( 'get_next_post_join', array( $this, 'filter_next_post_join' ) );257 remove_filter( 'get_next_post_where', array( $this, 'filter_next_post_where_with_join' ) );258 259 // Test "sort" filter when modifying ORDER BY clause260 add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );261 $this->go_to( get_permalink( $post_one->ID ) );262 $this->assertEquals( $post_four, get_adjacent_post( false, null, false ) );263 remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort' ) );264 265 // Test "sort" filter when modifying LIMIT clause266 add_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );267 $this->go_to( get_permalink( $post_one->ID ) );268 $this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );269 remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );270 271 // Test post-type specificity272 $this->go_to( get_permalink( $page_one ) );273 $this->assertEquals( $page_two, get_adjacent_post( false, null, false ) );274 275 $this->go_to( get_permalink( $page_two ) );276 $this->assertEquals( $page_one, get_adjacent_post( false, null, true ) );277 }278 279 /**280 * Filter callback for `test_legacy_get_adjacent_post_filters()`281 */282 function filter_previous_post_where( $where ) {283 $where .= " AND post_title !='Second'";284 return $where;285 }286 287 /**288 * Filter callback for `test_legacy_get_adjacent_post_filters()`289 */290 function filter_next_post_where( $where ) {291 $where .= " AND post_title !='Third'";292 return $where;293 }294 295 /**296 * Filter callback for `test_legacy_get_adjacent_post_filters()`297 */298 function override_previous_post_where_clause( $where ) {299 $where = "WHERE p.post_date < '2012-02-28'";300 return $where;301 }302 303 /**304 * Filter callback for `test_legacy_get_adjacent_post_filters()`305 */306 function filter_next_post_join( $join ) {307 global $wpdb;308 309 $join .= " INNER JOIN {$wpdb->postmeta} ON p.ID = {$wpdb->postmeta}.post_id";310 return $join;311 }312 313 /**314 * Filter callback for `test_legacy_get_adjacent_post_filters()`315 */316 function filter_next_post_where_with_join( $where ) {317 global $wpdb;318 319 $where .= " AND {$wpdb->postmeta}.meta_key = 'unit_test_meta'";320 return $where;321 }322 323 /**324 * Filter callback for `test_legacy_get_adjacent_post_filters()`325 */326 function filter_next_post_sort( $sort ) {327 return str_replace( 'p.post_date', 'p.post_title', $sort );328 }329 330 /**331 * Filter callback for `test_legacy_get_adjacent_post_filters()`332 */333 function filter_next_post_sort_limit( $sort ) {334 $sort = str_replace( 'LIMIT 0, 1', 'LIMIT 1, 2', $sort );335 return $sort;336 }337 191 }
Note: See TracChangeset
for help on using the changeset viewer.