Changeset 55085 for trunk/tests/phpunit/tests/link/getAdjacentPost.php
- Timestamp:
- 01/18/2023 11:18:36 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/link/getAdjacentPost.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link/getAdjacentPost.php
r52010 r55085 351 351 return $excluded_terms; 352 352 } 353 354 /** 355 * @ticket 41131 356 */ 357 public function test_get_adjacent_post_cache() { 358 // Need some sample posts to test adjacency. 359 $post_one = self::factory()->post->create_and_get( 360 array( 361 'post_title' => 'First', 362 'post_date' => '2012-01-01 12:00:00', 363 ) 364 ); 365 366 $post_two = self::factory()->post->create_and_get( 367 array( 368 'post_title' => 'Second', 369 'post_date' => '2012-02-01 12:00:00', 370 ) 371 ); 372 373 $post_three = self::factory()->post->create_and_get( 374 array( 375 'post_title' => 'Third', 376 'post_date' => '2012-03-01 12:00:00', 377 ) 378 ); 379 380 $post_four = self::factory()->post->create_and_get( 381 array( 382 'post_title' => 'Fourth', 383 'post_date' => '2012-04-01 12:00:00', 384 ) 385 ); 386 387 // Assign some terms. 388 wp_set_object_terms( $post_one->ID, 'WordPress', 'category', false ); 389 wp_set_object_terms( $post_three->ID, 'WordPress', 'category', false ); 390 391 wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false ); 392 wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false ); 393 394 // Test normal post adjacency. 395 $this->go_to( get_permalink( $post_two->ID ) ); 396 397 // Test getting the right result. 398 $first_run = get_adjacent_post( false, '', true ); 399 $this->assertEquals( $post_one, $first_run, 'Did not get first post when on second post' ); 400 $this->assertNotEquals( $post_two, $first_run, 'Got second post when on second post' ); 401 402 // Query count to test caching. 403 $num_queries = get_num_queries(); 404 $second_run = get_adjacent_post( false, '', true ); 405 $this->assertNotEquals( $post_two, $second_run, 'Got second post when on second post on second run' ); 406 $this->assertEquals( $post_one, $second_run, 'Did not get first post when on second post on second run' ); 407 $this->assertSame( $num_queries, get_num_queries() ); 408 409 // Test creating new post busts cache. 410 $post_five = self::factory()->post->create_and_get( 411 array( 412 'post_title' => 'Five', 413 'post_date' => '2012-04-01 12:00:00', 414 ) 415 ); 416 $num_queries = get_num_queries(); 417 418 $this->assertEquals( $post_one, get_adjacent_post( false, '', true ), 'Did not get first post after new post is added' ); 419 $this->assertSame( get_num_queries() - $num_queries, 1, 'Number of queries run was not one after new post is added' ); 420 421 $this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Did not get forth post after new post is added' ); 422 $num_queries = get_num_queries(); 423 $this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Did not get forth post after new post is added' ); 424 $this->assertSame( $num_queries, get_num_queries() ); 425 wp_set_object_terms( $post_four->ID, 'themes', 'post_tag', false ); 426 427 $num_queries = get_num_queries(); 428 $this->assertEquals( $post_four, get_adjacent_post( true, '', false ), 'Result of function call is wrong after after adding new term' ); 429 $this->assertSame( get_num_queries() - $num_queries, 2, 'Number of queries run was not two after adding new term' ); 430 } 353 431 }
Note: See TracChangeset
for help on using the changeset viewer.