Make WordPress Core

Ticket #56350: 56350-latest.diff

File 56350-latest.diff, 7.9 KB (added by mehulkaklotar, 2 years ago)

latest changes

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 3ec9a3a1346..a02a692c4ba 100644
    a b public function get_items( $request ) { 
    251251                        'search'         => 's',
    252252                        'slug'           => 'post_name__in',
    253253                        'status'         => 'post_status',
     254                        'exact_search'   => 'exact',
    254255                );
    255256
    256257                /*
    public function get_collection_params() { 
    28362837                        );
    28372838                }
    28382839
     2840                $query_params['exact_search'] = array(
     2841                        'description' => __( 'Use exact search instead of full search.' ),
     2842                        'type'        => 'boolean',
     2843                );
     2844
    28392845                $query_params['offset'] = array(
    28402846                        'description' => __( 'Offset the result set by a specific number of items.' ),
    28412847                        'type'        => 'integer',
  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
    index 27519610e86..c46e5845551 100644
    a b public function test_registered_query_params() { 
    216216                                'author_exclude',
    217217                                'before',
    218218                                'context',
     219                                'exact_search',
    219220                                'exclude',
    220221                                'include',
    221222                                'media_type',
  • tests/phpunit/tests/rest-api/rest-pages-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php
    index a6a9cfa3f46..1151c09e53c 100644
    a b public function test_registered_query_params() { 
    7373                                'author_exclude',
    7474                                'before',
    7575                                'context',
     76                                'exact_search',
    7677                                'exclude',
    7778                                'include',
    7879                                'menu_order',
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
    index 4b66145d801..d846dab51f8 100644
    a b public function test_registered_query_params() { 
    194194                                'categories',
    195195                                'categories_exclude',
    196196                                'context',
     197                                'exact_search',
    197198                                'exclude',
    198199                                'include',
    199200                                'modified_after',
    public function test_get_items_status_without_permissions() { 
    749750                }
    750751        }
    751752
     753        /**
     754         * @ticket 56350
     755         *
     756         * @dataProvider data_get_items_exact_search
     757         *
     758         * @param string $search_term  The search term.
     759         * @param bool   $exact_search Whether the search is an exact or general search.
     760         * @param int    $expected     The expected number of matching posts.
     761         */
     762        public function test_get_items_exact_search( $search_term, $exact_search, $expected ) {
     763                self::factory()->post->create(
     764                        array(
     765                                'post_title'   => 'Rye',
     766                                'post_content' => 'This is a post about Rye Bread',
     767                        )
     768                );
     769
     770                self::factory()->post->create(
     771                        array(
     772                                'post_title'   => 'Types of Bread',
     773                                'post_content' => 'Types of bread are White and Rye Bread',
     774                        )
     775                );
     776
     777                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     778                $request->set_param( 'search', $search_term );
     779                $request->set_param( 'exact_search', $exact_search );
     780                $response = rest_get_server()->dispatch( $request );
     781                $this->assertCount( $expected, $response->get_data() );
     782        }
     783
     784        /**
     785         * Data provider for test_get_items_exact_search().
     786         *
     787         * @return array[]
     788         */
     789        public function data_get_items_exact_search() {
     790                return array(
     791                        'general search, one exact match and one partial match' => array(
     792                                'search_term'  => 'Rye',
     793                                'exact_search' => false,
     794                                'expected'     => 2,
     795                        ),
     796                        'exact search, one exact match and one partial match' => array(
     797                                'search_term'  => 'Rye',
     798                                'exact_search' => true,
     799                                'expected'     => 1,
     800                        ),
     801                        'exact search, no match and one partial match' => array(
     802                                'search_term'  => 'Rye Bread',
     803                                'exact_search' => true,
     804                                'expected'     => 0,
     805                        ),
     806                );
     807        }
     808
    752809        public function test_get_items_order_and_orderby() {
    753810                self::factory()->post->create(
    754811                        array(
  • tests/qunit/fixtures/wp-api-generated.js

    diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js
    index 896322ed48d..b31f3b1d8e1 100644
    a b mockedApiResponse.Schema = { 
    362362                            "default": [],
    363363                            "required": false
    364364                        },
     365                        "exact_search": {
     366                            "description": "Use exact search instead of full search.",
     367                            "type": "boolean",
     368                            "required": false
     369                        },
    365370                        "offset": {
    366371                            "description": "Offset the result set by a specific number of items.",
    367372                            "type": "integer",
    mockedApiResponse.Schema = { 
    17001705                            "type": "integer",
    17011706                            "required": false
    17021707                        },
     1708                        "exact_search": {
     1709                            "description": "Use exact search instead of full search.",
     1710                            "type": "boolean",
     1711                            "required": false
     1712                        },
    17031713                        "offset": {
    17041714                            "description": "Offset the result set by a specific number of items.",
    17051715                            "type": "integer",
    mockedApiResponse.Schema = { 
    27822792                            "default": [],
    27832793                            "required": false
    27842794                        },
     2795                        "exact_search": {
     2796                            "description": "Use exact search instead of full search.",
     2797                            "type": "boolean",
     2798                            "required": false
     2799                        },
    27852800                        "offset": {
    27862801                            "description": "Offset the result set by a specific number of items.",
    27872802                            "type": "integer",
    mockedApiResponse.Schema = { 
    35093524                            "default": [],
    35103525                            "required": false
    35113526                        },
     3527                        "exact_search": {
     3528                            "description": "Use exact search instead of full search.",
     3529                            "type": "boolean",
     3530                            "required": false
     3531                        },
    35123532                        "offset": {
    35133533                            "description": "Offset the result set by a specific number of items.",
    35143534                            "type": "integer",
    mockedApiResponse.Schema = { 
    43064326                            "default": [],
    43074327                            "required": false
    43084328                        },
     4329                        "exact_search": {
     4330                            "description": "Use exact search instead of full search.",
     4331                            "type": "boolean",
     4332                            "required": false
     4333                        },
    43094334                        "offset": {
    43104335                            "description": "Offset the result set by a specific number of items.",
    43114336                            "type": "integer",
    mockedApiResponse.Schema = { 
    64576482                            "default": [],
    64586483                            "required": false
    64596484                        },
     6485                        "exact_search": {
     6486                            "description": "Use exact search instead of full search.",
     6487                            "type": "boolean",
     6488                            "required": false
     6489                        },
    64606490                        "offset": {
    64616491                            "description": "Offset the result set by a specific number of items.",
    64626492                            "type": "integer",