Make WordPress Core

Changeset 49132


Ignore:
Timestamp:
10/12/2020 07:52:57 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Introduce search post format handler.
This allows for clients to search the used post formats via the /wp/v2/search endpoint by using a type=post-format query parameter.
Fixes #51459.
Props andraganescu, zieladam, noisysocks, TimothyBlynJacobs.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r49120 r49132  
    277277        new WP_REST_Post_Search_Handler(),
    278278        new WP_REST_Term_Search_Handler(),
     279        new WP_REST_Post_Format_Search_Handler(),
    279280    );
    280281
  • trunk/src/wp-settings.php

    r49109 r49132  
    270270require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-post-search-handler.php';
    271271require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-term-search-handler.php';
     272require ABSPATH . WPINC . '/rest-api/search/class-wp-rest-post-format-search-handler.php';
    272273require ABSPATH . WPINC . '/sitemaps.php';
    273274require ABSPATH . WPINC . '/sitemaps/class-wp-sitemaps.php';
  • trunk/tests/phpunit/tests/rest-api/rest-search-controller.php

    r49103 r49132  
    5555     */
    5656    public static function wpSetUpBeforeClass( $factory ) {
     57        add_theme_support( 'post-formats' );
     58
    5759        self::$my_title_post_ids = $factory->post->create_many(
    5860            4,
     
    7880        );
    7981
     82        set_post_format( self::$my_title_post_ids[0], 'aside' );
     83
    8084        self::$my_category_id = $factory->term->create(
    8185            array(
     
    97101     */
    98102    public static function wpTearDownAfterClass() {
     103        remove_theme_support( 'post-formats' );
     104
    99105        $post_ids = array_merge(
    100106            self::$my_title_post_ids,
     
    705711
    706712    /**
     713     * Search through post formats of any type.
     714     *
     715     * @ticket 51459
     716     */
     717    public function test_get_items_search_type_post_format() {
     718        $response = $this->do_request_with_params(
     719            array(
     720                'per_page' => 100,
     721                'type'     => 'post-format',
     722            )
     723        );
     724        $this->assertEquals( 200, $response->get_status() );
     725        $this->assertContains(
     726            'Aside',
     727            wp_list_pluck( $response->get_data(), 'title' )
     728        );
     729    }
     730
     731    /**
     732     * Search through all that matches a 'Aside' search.
     733     *
     734     * @ticket 51459
     735     */
     736    public function test_get_items_search_for_test_post_format() {
     737        $response = $this->do_request_with_params(
     738            array(
     739                'per_page' => 100,
     740                'search'   => 'Aside',
     741                'type'     => 'post-format',
     742            )
     743        );
     744
     745        $this->assertEquals( 200, $response->get_status() );
     746        $this->assertContains(
     747            'Aside',
     748            wp_list_pluck( $response->get_data(), 'title' )
     749        );
     750    }
     751
     752    /**
     753     * Searching for a post format that doesn't exist should return an empty
     754     * result.
     755     *
     756     * @ticket 51459
     757     */
     758    public function test_get_items_search_for_missing_post_format() {
     759        $response = $this->do_request_with_params(
     760            array(
     761                'per_page' => 100,
     762                'search'   => 'Doesn\'t exist',
     763                'type'     => 'post-format',
     764            )
     765        );
     766
     767        $this->assertEquals( 200, $response->get_status() );
     768        $this->assertEmpty( $response->get_data() );
     769    }
     770
     771    /**
    707772     * Perform a REST request to our search endpoint with given parameters.
    708773     */
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r49109 r49132  
    45114511                            "enum": [
    45124512                                "post",
    4513                                 "term"
     4513                                "term",
     4514                                "post-format"
    45144515                            ],
    45154516                            "description": "Limit results to items of an object type.",
Note: See TracChangeset for help on using the changeset viewer.