Changeset 60359
- Timestamp:
- 06/27/2025 08:45:08 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php (modified) (6 diffs)
-
tests/phpunit/tests/rest-api/rest-global-styles-controller.php (modified) (4 diffs)
-
tests/phpunit/tests/rest-api/rest-schema-setup.php (modified) (1 diff)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
r59048 r60359 89 89 register_rest_route( 90 90 $this->namespace, 91 '/' . $this->rest_base . '/(?P<id>[\/\ w-]+)',91 '/' . $this->rest_base . '/(?P<id>[\/\d+]+)', 92 92 array( 93 93 array( … … 97 97 'args' => array( 98 98 'id' => array( 99 'description' => __( 'The id of a template' ), 100 'type' => 'string', 101 'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ), 99 'description' => __( 'ID of global styles config.' ), 100 'type' => 'integer', 102 101 ), 103 102 ), … … 116 115 117 116 /** 118 * Sanitize the global styles ID orstylesheet to decode endpoint.117 * Sanitize the global styles stylesheet to decode endpoint. 119 118 * For example, `wp/v2/global-styles/twentytwentytwo%200.4.0` 120 119 * would be decoded to `twentytwentytwo 0.4.0`. … … 122 121 * @since 5.9.0 123 122 * 124 * @param string $ id_or_stylesheet Global styles ID orstylesheet.125 * @return string Sanitized global styles ID orstylesheet.126 */ 127 public function _sanitize_global_styles_callback( $ id_or_stylesheet ) {128 return urldecode( $ id_or_stylesheet );123 * @param string $stylesheet Global styles stylesheet. 124 * @return string Sanitized global styles stylesheet. 125 */ 126 public function _sanitize_global_styles_callback( $stylesheet ) { 127 return urldecode( $stylesheet ); 129 128 } 130 129 … … 140 139 $error = new WP_Error( 141 140 'rest_global_styles_not_found', 142 __( 'No global styles config exist with that id.' ),141 __( 'No global styles config exists with that ID.' ), 143 142 array( 'status' => 404 ) 144 143 ); … … 465 464 'id' => array( 466 465 'description' => __( 'ID of global styles config.' ), 467 'type' => ' string',466 'type' => 'integer', 468 467 'context' => array( 'embed', 'view', 'edit' ), 469 468 'readonly' => true, -
trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php
r59048 r60359 134 134 $routes = rest_get_server()->get_routes(); 135 135 $this->assertArrayHasKey( 136 '/wp/v2/global-styles/(?P<id>[\/\ w-]+)',136 '/wp/v2/global-styles/(?P<id>[\/\d+]+)', 137 137 $routes, 138 138 'Single global style based on the given ID route does not exist' … … 140 140 $this->assertCount( 141 141 2, 142 $routes['/wp/v2/global-styles/(?P<id>[\/\ w-]+)'],142 $routes['/wp/v2/global-styles/(?P<id>[\/\d+]+)'], 143 143 'Single global style based on the given ID route does not have exactly two elements' 144 144 ); … … 409 409 '2 subdirectories deep' => array( 410 410 'theme_dirname' => 'subdir/subsubdir/mytheme', 411 'expected' => 'rest_ global_styles_not_found',411 'expected' => 'rest_no_route', 412 412 ), 413 413 ); … … 777 777 } 778 778 } 779 780 /** 781 * Test that the route accepts integer IDs. 782 * 783 * @ticket 61911 784 */ 785 public function test_global_styles_route_accepts_integer_id() { 786 wp_set_current_user( self::$admin_id ); 787 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id ); 788 $response = rest_get_server()->dispatch( $request ); 789 790 $this->assertEquals( 200, $response->get_status() ); 791 792 $data = $response->get_data(); 793 $this->assertIsInt( $data['id'] ); 794 $this->assertSame( self::$global_styles_id, $data['id'] ); 795 } 796 797 /** 798 * Test that the schema defines ID as an integer. 799 * 800 * @ticket 61911 801 */ 802 public function test_global_styles_schema_id_type() { 803 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/global-styles/' . self::$global_styles_id ); 804 $response = rest_get_server()->dispatch( $request ); 805 806 $data = $response->get_data(); 807 $schema = $data['schema']; 808 809 $this->assertArrayHasKey( 'properties', $schema ); 810 $this->assertArrayHasKey( 'id', $schema['properties'] ); 811 $this->assertArrayHasKey( 'type', $schema['properties']['id'] ); 812 $this->assertSame( 'integer', $schema['properties']['id']['type'] ); 813 } 814 815 /** 816 * Test that the route argument schema defines ID as an integer. 817 * 818 * @ticket 61911 819 */ 820 public function test_global_styles_route_args_schema() { 821 $routes = rest_get_server()->get_routes(); 822 $route_data = $routes['/wp/v2/global-styles/(?P<id>[\/\d+]+)']; 823 824 $this->assertArrayHasKey( 'args', $route_data[0] ); 825 $this->assertArrayHasKey( 'id', $route_data[0]['args'] ); 826 $this->assertArrayHasKey( 'type', $route_data[0]['args']['id'] ); 827 $this->assertSame( 'integer', $route_data[0]['args']['id']['type'] ); 828 } 779 829 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r59532 r60359 134 134 '/wp/v2/comments', 135 135 '/wp/v2/comments/(?P<id>[\\d]+)', 136 '/wp/v2/global-styles/(?P<id>[\/\ w-]+)',136 '/wp/v2/global-styles/(?P<id>[\/\d+]+)', 137 137 '/wp/v2/global-styles/(?P<parent>[\d]+)/revisions', 138 138 '/wp/v2/global-styles/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', -
trunk/tests/qunit/fixtures/wp-api-generated.js
r60197 r60359 6897 6897 ] 6898 6898 }, 6899 "/wp/v2/global-styles/(?P<id>[\\/\\ w-]+)": {6899 "/wp/v2/global-styles/(?P<id>[\\/\\d+]+)": { 6900 6900 "namespace": "wp/v2", 6901 6901 "methods": [ … … 6915 6915 "args": { 6916 6916 "id": { 6917 "description": " The id of a template",6918 "type": " string",6917 "description": "ID of global styles config.", 6918 "type": "integer", 6919 6919 "required": false 6920 6920 }
Note: See TracChangeset
for help on using the changeset viewer.