Changeset 52017
- Timestamp:
- 11/05/2021 02:29:32 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
r51786 r52017 16 16 */ 17 17 class WP_REST_Themes_Controller extends WP_REST_Controller { 18 19 const PATTERN = '[^.\/]+(?:\/[^.\/]+)?'; 18 20 19 21 /** … … 51 53 register_rest_route( 52 54 $this->namespace, 53 '/' . $this->rest_base . '/(?P<stylesheet>[\w-]+)',55 sprintf( '/%s/(?P<stylesheet>%s)', $this->rest_base, self::PATTERN ), 54 56 array( 55 57 'args' => array( -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r51568 r52017 138 138 '/wp/v2/templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', 139 139 '/wp/v2/themes', 140 '/wp/v2/themes/(?P<stylesheet>[ \w-]+)',140 '/wp/v2/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)', 141 141 '/wp/v2/plugins', 142 142 '/wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?)', -
trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php
r51568 r52017 152 152 $routes = rest_get_server()->get_routes(); 153 153 $this->assertArrayHasKey( self::$themes_route, $routes ); 154 $this->assertArrayHasKey( self::$themes_route . '/(?P<stylesheet>[\\w-]+)', $routes ); 154 $this->assertArrayHasKey( 155 sprintf( '%s/(?P<stylesheet>%s)', self::$themes_route, WP_REST_Themes_Controller::PATTERN ), 156 $routes 157 ); 155 158 } 156 159 … … 1283 1286 1284 1287 /** 1288 * @ticket 54349 1289 */ 1290 public function test_get_item_subdirectory_theme() { 1291 wp_set_current_user( self::$admin_id ); 1292 $request = new WP_REST_Request( 'GET', self::$themes_route . '/subdir/theme2' ); 1293 $response = rest_do_request( $request ); 1294 1295 $this->assertSame( 200, $response->get_status() ); 1296 $this->assertSame( 'My Subdir Theme', $response->get_data()['name']['raw'] ); 1297 } 1298 1299 /** 1300 * @ticket 54349 1301 */ 1302 public function test_can_support_further_routes() { 1303 register_rest_route( 1304 'wp/v2', 1305 sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ), 1306 array( 1307 'callback' => function ( WP_REST_Request $request ) { 1308 return $request['stylesheet']; 1309 }, 1310 'permission_callback' => '__return_true', 1311 ) 1312 ); 1313 1314 wp_set_current_user( self::$admin_id ); 1315 1316 $response = rest_do_request( self::$themes_route . '/default//test' ); 1317 $this->assertSame( 'default', $response->get_data() ); 1318 1319 $response = rest_do_request( self::$themes_route . '/subdir/theme2//test' ); 1320 $this->assertSame( 'subdir/theme2', $response->get_data() ); 1321 } 1322 1323 /** 1285 1324 * The delete_item() method does not exist for themes. 1286 1325 */ -
trunk/tests/qunit/fixtures/wp-api-generated.js
r52016 r52017 6710 6710 } 6711 6711 }, 6712 "/wp/v2/themes/(?P<stylesheet>[ \\w-]+)": {6712 "/wp/v2/themes/(?P<stylesheet>[^.\\/]+(?:\\/[^.\\/]+)?)": { 6713 6713 "namespace": "wp/v2", 6714 6714 "methods": [
Note: See TracChangeset
for help on using the changeset viewer.