Changeset 49103
- Timestamp:
- 10/08/2020 01:30:25 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r49082 r49103 269 269 $controller->register_routes(); 270 270 271 $search_handlers = array( 272 new WP_REST_Post_Search_Handler(), 273 new WP_REST_Term_Search_Handler(), 274 ); 275 271 276 /** 272 277 * Filters the search handlers to use in the REST search controller. … … 278 283 * Default is only a handler for posts. 279 284 */ 280 $search_handlers = apply_filters( 'wp_rest_search_handlers', array( new WP_REST_Post_Search_Handler() ));285 $search_handlers = apply_filters( 'wp_rest_search_handlers', $search_handlers ); 281 286 282 287 $controller = new WP_REST_Search_Controller( $search_handlers ); -
trunk/src/wp-settings.php
r48334 r49103 267 267 require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-search-handler.php'; 268 268 require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-post-search-handler.php'; 269 require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-term-search-handler.php'; 269 270 require ABSPATH . WPINC . '/sitemaps.php'; 270 271 require ABSPATH . WPINC . '/sitemaps/class-wp-sitemaps.php'; -
trunk/tests/phpunit/tests/rest-api/rest-search-controller.php
r48939 r49103 36 36 37 37 /** 38 * Categories. 39 * 40 * @var int 41 */ 42 private static $my_category_id; 43 44 /** 45 * Tags. 46 * 47 * @var int 48 */ 49 private static $my_tag_id; 50 51 /** 38 52 * Create fake data before our tests run. 39 53 * … … 61 75 array( 62 76 'post_content' => 'my-foocontent', 77 ) 78 ); 79 80 self::$my_category_id = $factory->term->create( 81 array( 82 'taxonomy' => 'category', 83 'name' => 'Test Category', 84 ) 85 ); 86 87 self::$my_tag_id = $factory->term->create( 88 array( 89 'taxonomy' => 'post_tag', 90 'name' => 'Test Tag', 63 91 ) 64 92 ); … … 77 105 foreach ( $post_ids as $post_id ) { 78 106 wp_delete_post( $post_id, true ); 107 } 108 109 $term_ids = array( 110 self::$my_category_id, 111 self::$my_tag_id, 112 ); 113 114 foreach ( $term_ids as $term_id ) { 115 wp_delete_term( $term_id, true ); 79 116 } 80 117 } … … 516 553 517 554 /** 555 * Search through terms of any type. 556 * 557 * @ticket 51458 558 */ 559 public function test_get_items_search_type_term() { 560 $response = $this->do_request_with_params( 561 array( 562 'per_page' => 100, 563 'type' => 'term', 564 ) 565 ); 566 $this->assertEquals( 200, $response->get_status() ); 567 $this->assertEqualSets( 568 array( 569 0 => 1, // That is the default category. 570 self::$my_category_id, 571 self::$my_tag_id, 572 ), 573 wp_list_pluck( $response->get_data(), 'id' ) 574 ); 575 } 576 577 /** 578 * Search through terms of subtype 'category'. 579 * 580 * @ticket 51458 581 */ 582 public function test_get_items_search_type_term_subtype_category() { 583 $response = $this->do_request_with_params( 584 array( 585 'per_page' => 100, 586 'type' => 'term', 587 'subtype' => 'category', 588 ) 589 ); 590 591 $this->assertEquals( 200, $response->get_status() ); 592 $this->assertEqualSets( 593 array( 594 0 => 1, // That is the default category. 595 self::$my_category_id, 596 ), 597 wp_list_pluck( $response->get_data(), 'id' ) 598 ); 599 } 600 601 /** 602 * Search through posts of an invalid post type. 603 * 604 * @ticket 51458 605 */ 606 public function test_get_items_search_term_subtype_invalid() { 607 $response = $this->do_request_with_params( 608 array( 609 'per_page' => 100, 610 'type' => 'term', 611 'subtype' => 'invalid', 612 ) 613 ); 614 615 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 616 } 617 618 /** 619 * Search through posts and pages. 620 * 621 * @ticket 51458 622 */ 623 public function test_get_items_search_categories_and_tags() { 624 $response = $this->do_request_with_params( 625 array( 626 'per_page' => 100, 627 'type' => 'term', 628 'subtype' => 'category,post_tag', 629 ) 630 ); 631 $this->assertEquals( 200, $response->get_status() ); 632 $this->assertEqualSets( 633 array( 634 0 => 1, // This is the default category. 635 self::$my_category_id, 636 self::$my_tag_id, 637 ), 638 wp_list_pluck( $response->get_data(), 'id' ) 639 ); 640 } 641 642 /** 643 * Search through all that matches a 'Test Category' search. 644 * 645 * @ticket 51458 646 */ 647 public function test_get_items_search_for_test_category() { 648 $response = $this->do_request_with_params( 649 array( 650 'per_page' => 100, 651 'search' => 'Test Category', 652 'type' => 'term', 653 ) 654 ); 655 656 $this->assertEquals( 200, $response->get_status() ); 657 $this->assertEqualSets( 658 array( 659 self::$my_category_id, 660 ), 661 wp_list_pluck( $response->get_data(), 'id' ) 662 ); 663 } 664 665 /** 666 * Search through all that matches a 'Test Tag' search. 667 * 668 * @ticket 51458 669 */ 670 public function test_get_items_search_for_test_tag() { 671 $response = $this->do_request_with_params( 672 array( 673 'per_page' => 100, 674 'search' => 'Test Tag', 675 'type' => 'term', 676 ) 677 ); 678 679 $this->assertEquals( 200, $response->get_status() ); 680 $this->assertEqualSets( 681 array( 682 self::$my_tag_id, 683 ), 684 wp_list_pluck( $response->get_data(), 'id' ) 685 ); 686 } 687 688 /** 689 * Searching for a term that doesn't exist should return an empty result. 690 * 691 * @ticket 51458 692 */ 693 public function test_get_items_search_for_missing_term() { 694 $response = $this->do_request_with_params( 695 array( 696 'per_page' => 100, 697 'search' => 'Doesn\'t exist', 698 'type' => 'term', 699 ) 700 ); 701 702 $this->assertEquals( 200, $response->get_status() ); 703 $this->assertEmpty( $response->get_data() ); 704 } 705 706 /** 518 707 * Perform a REST request to our search endpoint with given parameters. 519 708 */ -
trunk/tests/qunit/fixtures/wp-api-generated.js
r49031 r49103 4414 4414 "default": "post", 4415 4415 "enum": [ 4416 "post" 4416 "post", 4417 "term" 4417 4418 ], 4418 4419 "description": "Limit results to items of an object type.", … … 4428 4429 "post", 4429 4430 "page", 4431 "category", 4432 "post_tag", 4430 4433 "any" 4431 4434 ],
Note: See TracChangeset
for help on using the changeset viewer.