- Timestamp:
- 03/02/2025 10:05:08 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php
r59630 r59899 246 246 247 247 /** 248 * @ticket 58524 249 * 250 * @covers WP_REST_Global_Styles_Controller::get_items 251 */ 252 public function test_get_items_missing_parent() { 253 wp_set_current_user( self::$admin_id ); 254 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); 248 * @dataProvider data_readable_http_methods 249 * @ticket 58524 250 * @ticket 56481 251 * 252 * @covers WP_REST_Global_Styles_Controller::get_items 253 * 254 * @param string $method The HTTP method to use. 255 */ 256 public function test_get_items_missing_parent( $method ) { 257 wp_set_current_user( self::$admin_id ); 258 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); 255 259 $response = rest_get_server()->dispatch( $request ); 256 260 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); 261 } 262 263 /** 264 * Data provider intended to provide HTTP method names for testing GET and HEAD requests. 265 * 266 * @return array 267 */ 268 public static function data_readable_http_methods() { 269 return array( 270 'GET request' => array( 'GET' ), 271 'HEAD request' => array( 'HEAD' ), 272 ); 257 273 } 258 274 … … 312 328 313 329 /** 330 * @ticket 56481 331 * 332 * @covers WP_REST_Global_Styles_Controller::prepare_item_for_response 333 */ 334 public function test_get_items_should_return_no_response_body_for_head_requests() { 335 wp_set_current_user( self::$admin_id ); 336 $request = new WP_REST_Request( 'HEAD', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 337 $response = rest_get_server()->dispatch( $request ); 338 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 339 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 340 } 341 342 /** 314 343 * @ticket 59810 315 344 * … … 328 357 329 358 /** 359 * @ticket 56481 360 * 361 * @covers WP_REST_Global_Styles_Controller::get_item 362 * @covers WP_REST_Global_Styles_Controller::prepare_item_for_response 363 */ 364 public function test_get_item_should_return_no_response_body_for_head_requests() { 365 wp_set_current_user( self::$admin_id ); 366 $request = new WP_REST_Request( 'HEAD', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $this->revision_1_id ); 367 $response = rest_get_server()->dispatch( $request ); 368 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 369 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 370 } 371 372 /** 373 * @dataProvider data_readable_http_methods 330 374 * @ticket 59810 375 * @ticket 56481 331 376 * 332 377 * @covers WP_REST_Global_Styles_Controller::get_revision 333 */ 334 public function test_get_item_invalid_revision_id_should_error() { 378 * 379 * @param string $method The HTTP method to use. 380 */ 381 public function test_get_item_invalid_revision_id_should_error( $method ) { 335 382 wp_set_current_user( self::$admin_id ); 336 383 337 384 $expected_error = 'rest_post_invalid_id'; 338 385 $expected_status = 404; 339 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/20000001' );386 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/20000001' ); 340 387 $response = rest_get_server()->dispatch( $request ); 341 388 … … 420 467 421 468 /** 469 * @dataProvider data_readable_http_methods 422 470 * @ticket 58524 423 471 * @ticket 60131 472 * @ticket 56481 424 473 * 425 474 * @covers WP_REST_Global_Styles_Controller::get_item_permissions_check 426 */ 427 public function test_get_item_permissions_check() { 475 * 476 * @param string $method The HTTP method to use. 477 */ 478 public function test_get_item_permissions_check( $method ) { 428 479 wp_set_current_user( self::$author_id ); 429 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );480 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 430 481 $response = rest_get_server()->dispatch( $request ); 431 482 … … 436 487 * Tests the pagination header of the first page. 437 488 * 438 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_pagination_header_of_the_first_page 439 * 440 * @ticket 58524 441 * 442 * @covers WP_REST_Global_Styles_Controller::get_items 443 */ 444 public function test_get_items_pagination_header_of_the_first_page() { 489 * @dataProvider data_readable_http_methods 490 * @ticket 58524 491 * @ticket 56481 492 * 493 * @covers WP_REST_Global_Styles_Controller::get_items 494 * 495 * @param string $method The HTTP method to use. 496 */ 497 public function test_get_items_pagination_header_of_the_first_page( $method ) { 445 498 wp_set_current_user( self::$admin_id ); 446 499 … … 450 503 $page = 1; // First page. 451 504 452 $request = new WP_REST_Request( 'GET', $rest_route );505 $request = new WP_REST_Request( $method, $rest_route ); 453 506 $request->set_query_params( 454 507 array( … … 477 530 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_pagination_header_of_the_last_page 478 531 * 479 * @ticket 58524 480 * 481 * @covers WP_REST_Global_Styles_Controller::get_items 482 */ 483 public function test_get_items_pagination_header_of_the_last_page() { 532 * @dataProvider data_readable_http_methods 533 * @ticket 58524 534 * @ticket 56481 535 * 536 * @covers WP_REST_Global_Styles_Controller::get_items 537 * 538 * @param string $method The HTTP method to use. 539 */ 540 public function test_get_items_pagination_header_of_the_last_page( $method ) { 484 541 wp_set_current_user( self::$admin_id ); 485 542 … … 489 546 $page = 2; // Last page. 490 547 491 $request = new WP_REST_Request( 'GET', $rest_route );548 $request = new WP_REST_Request( $method, $rest_route ); 492 549 $request->set_query_params( 493 550 array( … … 515 572 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_per_page_should_error 516 573 * 517 * @ticket 58524 518 * 519 * @covers WP_REST_Global_Styles_Controller::get_items 520 */ 521 public function test_get_items_invalid_per_page_should_error() { 574 * @dataProvider data_readable_http_methods 575 * @ticket 58524 576 * @ticket 56481 577 * 578 * @covers WP_REST_Global_Styles_Controller::get_items 579 * 580 * @param string $method The HTTP method to use. 581 */ 582 public function test_get_items_invalid_per_page_should_error( $method ) { 522 583 wp_set_current_user( self::$admin_id ); 523 584 … … 526 587 $expected_status = 400; 527 588 528 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );589 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 529 590 $request->set_param( 'per_page', $per_page ); 530 591 $response = rest_get_server()->dispatch( $request ); … … 537 598 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_out_of_bounds_page_should_error 538 599 * 539 * @ticket 58524 540 * 541 * @covers WP_REST_Global_Styles_Controller::get_items 542 */ 543 public function test_get_items_out_of_bounds_page_should_error() { 600 * @dataProvider data_readable_http_methods 601 * @ticket 58524 602 * @ticket 56481 603 * 604 * @covers WP_REST_Global_Styles_Controller::get_items 605 * 606 * @param string $method The HTTP method to use. 607 */ 608 public function test_get_items_out_of_bounds_page_should_error( $method ) { 544 609 wp_set_current_user( self::$admin_id ); 545 610 … … 550 615 $expected_status = 400; 551 616 552 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );617 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 553 618 $request->set_query_params( 554 619 array( … … 566 631 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_max_pages_should_error 567 632 * 568 * @ticket 58524 569 * 570 * @covers WP_REST_Global_Styles_Controller::get_items 571 */ 572 public function test_get_items_invalid_max_pages_should_error() { 633 * @dataProvider data_readable_http_methods 634 * @ticket 58524 635 * @ticket 56481 636 * 637 * @covers WP_REST_Global_Styles_Controller::get_items 638 * 639 * @param string $method The HTTP method to use. 640 */ 641 public function test_get_items_invalid_max_pages_should_error( $method ) { 573 642 wp_set_current_user( self::$admin_id ); 574 643 … … 578 647 $expected_status = 400; 579 648 580 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );649 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 581 650 $request->set_query_params( 582 651 array( … … 690 759 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_total_revisions_offset_should_return_empty_data 691 760 * 692 * @ticket 58524 693 * 694 * @covers WP_REST_Global_Styles_Controller::get_items 695 */ 696 public function test_get_items_total_revisions_offset_should_return_empty_data() { 761 * @dataProvider data_readable_http_methods 762 * @ticket 58524 763 * @ticket 56481 764 * 765 * @covers WP_REST_Global_Styles_Controller::get_items 766 * 767 * @param string $method The HTTP method to use. 768 */ 769 public function test_get_items_total_revisions_offset_should_return_empty_data( $method ) { 697 770 wp_set_current_user( self::$admin_id ); 698 771 … … 702 775 $expected_status = 400; 703 776 704 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );777 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 705 778 $request->set_query_params( 706 779 array( … … 718 791 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_out_of_bound_offset_should_error 719 792 * 720 * @ticket 58524 721 * 722 * @covers WP_REST_Global_Styles_Controller::get_items 723 */ 724 public function test_get_items_out_of_bound_offset_should_error() { 793 * @dataProvider data_readable_http_methods 794 * @ticket 58524 795 * @ticket 56481 796 * 797 * @covers WP_REST_Global_Styles_Controller::get_items 798 * 799 * @param string $method The HTTP method to use. 800 */ 801 public function test_get_items_out_of_bound_offset_should_error( $method ) { 725 802 wp_set_current_user( self::$admin_id ); 726 803 … … 730 807 $expected_status = 400; 731 808 732 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );809 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 733 810 $request->set_query_params( 734 811 array( … … 746 823 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_impossible_high_number_offset_should_error 747 824 * 748 * @ticket 58524 749 * 750 * @covers WP_REST_Global_Styles_Controller::get_items 751 */ 752 public function test_get_items_impossible_high_number_offset_should_error() { 825 * @dataProvider data_readable_http_methods 826 * @ticket 58524 827 * @ticket 56481 828 * 829 * @covers WP_REST_Global_Styles_Controller::get_items 830 * 831 * @param string $method The HTTP method to use. 832 */ 833 public function test_get_items_impossible_high_number_offset_should_error( $method ) { 753 834 wp_set_current_user( self::$admin_id ); 754 835 … … 758 839 $expected_status = 400; 759 840 760 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );841 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 761 842 $request->set_query_params( 762 843 array( … … 774 855 * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_offset_should_error 775 856 * 776 * @ticket 58524 777 * 778 * @covers WP_REST_Global_Styles_Controller::get_items 779 */ 780 public function test_get_items_invalid_offset_should_error() { 857 * @dataProvider data_readable_http_methods 858 * @ticket 58524 859 * @ticket 56481 860 * 861 * @covers WP_REST_Global_Styles_Controller::get_items 862 * 863 * @param string $method The HTTP method to use. 864 */ 865 public function test_get_items_invalid_offset_should_error( $method ) { 781 866 wp_set_current_user( self::$admin_id ); 782 867 … … 786 871 $expected_status = 400; 787 872 788 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );873 $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); 789 874 $request->set_query_params( 790 875 array(
Note: See TracChangeset
for help on using the changeset viewer.