Make WordPress Core


Ignore:
Timestamp:
01/31/2024 10:39:04 AM (6 months ago)
Author:
youknowriad
Message:

REST API: Add route for single styles revisions.

Adds a route for single global styles revisions: /wp/v2/global-styles/${ parentId }/revisions/${ revisionsId }
This fixes the getRevision actions in the core-data package.

Props ramonopoly, get_dave.
Fixes #59810.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php

    r56714 r57494  
    227227    /**
    228228     * @ticket 58524
     229     * @ticket 59810
    229230     *
    230231     * @covers WP_REST_Global_Styles_Controller::register_routes
     
    236237            $routes,
    237238            'Global style revisions based on the given parentID route does not exist.'
     239        );
     240        $this->assertArrayHasKey(
     241            '/wp/v2/global-styles/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
     242            $routes,
     243            'Single global style revisions based on the given parentID and revision ID route does not exist.'
    238244        );
    239245    }
     
    303309        $this->assertSame( $this->revision_1_id, $data[2]['id'] );
    304310        $this->check_get_revision_response( $data[2], $this->revision_1 );
     311    }
     312
     313    /**
     314     * @ticket 59810
     315     *
     316     * @covers WP_REST_Global_Styles_Controller::get_item
     317     */
     318    public function test_get_item() {
     319        wp_set_current_user( self::$admin_id );
     320
     321        $request  = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $this->revision_1_id );
     322        $response = rest_get_server()->dispatch( $request );
     323        $data     = $response->get_data();
     324
     325        $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
     326        $this->check_get_revision_response( $data, $this->revision_1 );
     327    }
     328
     329    /**
     330     * @ticket 59810
     331     *
     332     * @covers WP_REST_Global_Styles_Controller::get_revision
     333     */
     334    public function test_get_item_invalid_revision_id_should_error() {
     335        wp_set_current_user( self::$admin_id );
     336
     337        $expected_error  = 'rest_post_invalid_id';
     338        $expected_status = 404;
     339        $request         = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/20000001' );
     340        $response        = rest_get_server()->dispatch( $request );
     341
     342        $this->assertErrorResponse( $expected_error, $response, $expected_status );
    305343    }
    306344
     
    798836     * @doesNotPerformAssertions
    799837     */
    800     public function test_get_item() {
    801         // Controller does not implement get_item().
    802     }
    803 
    804     /**
    805      * @doesNotPerformAssertions
    806      */
    807838    public function test_create_item() {
    808839        // Controller does not implement create_item().
Note: See TracChangeset for help on using the changeset viewer.