- Timestamp:
- 09/17/2024 09:56:18 PM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r58326 r59034 207 207 'search', 208 208 'search_columns', 209 'search_semantics', 209 210 'slug', 210 211 'status', … … 764 765 $this->assertNotEquals( $draft_id, $post['id'] ); 765 766 } 767 } 768 769 /** 770 * @ticket 56350 771 * 772 * @dataProvider data_get_items_exact_search 773 * 774 * @param string $search_term The search term. 775 * @param bool $exact_search Whether the search is an exact or general search. 776 * @param int $expected The expected number of matching posts. 777 */ 778 public function test_get_items_exact_search( $search_term, $exact_search, $expected ) { 779 self::factory()->post->create( 780 array( 781 'post_title' => 'Rye', 782 'post_content' => 'This is a post about Rye Bread', 783 ) 784 ); 785 786 self::factory()->post->create( 787 array( 788 'post_title' => 'Types of Bread', 789 'post_content' => 'Types of bread are White and Rye Bread', 790 ) 791 ); 792 793 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 794 $request['search'] = $search_term; 795 if ( $exact_search ) { 796 $request['search_semantics'] = 'exact'; 797 } 798 $response = rest_get_server()->dispatch( $request ); 799 $this->assertCount( $expected, $response->get_data() ); 800 } 801 802 /** 803 * Data provider for test_get_items_exact_search(). 804 * 805 * @return array[] 806 */ 807 public function data_get_items_exact_search() { 808 return array( 809 'general search, one exact match and one partial match' => array( 810 'search_term' => 'Rye', 811 'exact_search' => false, 812 'expected' => 2, 813 ), 814 'exact search, one exact match and one partial match' => array( 815 'search_term' => 'Rye', 816 'exact_search' => true, 817 'expected' => 1, 818 ), 819 'exact search, no match and one partial match' => array( 820 'search_term' => 'Rye Bread', 821 'exact_search' => true, 822 'expected' => 0, 823 ), 824 ); 766 825 } 767 826
Note: See TracChangeset
for help on using the changeset viewer.