- Timestamp:
- 06/14/2022 12:40:29 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r52389 r53498 30 30 private $test_file2; 31 31 32 /** 33 * @var array The recorded posts query clauses. 34 */ 35 protected $posts_clauses; 36 32 37 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 33 38 self::$superadmin_id = $factory->user->create( … … 86 91 $this->test_file2 = get_temp_dir() . 'codeispoetry.png'; 87 92 copy( $orig_file2, $this->test_file2 ); 93 94 add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 ); 95 add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 ); 96 } 97 98 public function wpSetUpBeforeRequest( $result ) { 99 $this->posts_clauses = array(); 100 return $result; 101 } 102 103 public function save_posts_clauses( $clauses ) { 104 $this->posts_clauses[] = $clauses; 105 return $clauses; 88 106 } 89 107 … … 618 636 $this->assertCount( 1, $data ); 619 637 $this->assertSame( $id2, $data[0]['id'] ); 638 } 639 640 /** 641 * @ticket 55677 642 */ 643 public function test_get_items_avoid_duplicated_count_query_if_no_items() { 644 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 645 $request->set_param( 'media_type', 'video' ); 646 647 $response = rest_get_server()->dispatch( $request ); 648 649 $this->assertCount( 1, $this->posts_clauses ); 650 651 $headers = $response->get_headers(); 652 653 $this->assertSame( 0, $headers['X-WP-Total'] ); 654 $this->assertSame( 0, $headers['X-WP-TotalPages'] ); 655 } 656 657 /** 658 * @ticket 55677 659 */ 660 public function test_get_items_with_empty_page_runs_count_query_after() { 661 $this->factory->attachment->create_object( 662 $this->test_file, 663 0, 664 array( 665 'post_date' => '2022-06-12T00:00:00Z', 666 'post_mime_type' => 'image/jpeg', 667 'post_excerpt' => 'A sample caption', 668 ) 669 ); 670 671 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 672 $request->set_param( 'media_type', 'image' ); 673 $request->set_param( 'page', 2 ); 674 675 $response = rest_get_server()->dispatch( $request ); 676 677 $this->assertCount( 2, $this->posts_clauses ); 678 679 $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 ); 620 680 } 621 681
Note: See TracChangeset
for help on using the changeset viewer.