REST API: Sort widget types by their id.

Fixes #53303.
Props spacedmonkey.


git-svn-id: https://develop.svn.wordpress.org/trunk@51882 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs 2021-10-02 21:43:26 +00:00
parent f660632c9c
commit 6194de49dc
2 changed files with 18 additions and 0 deletions

View File

@ -237,6 +237,8 @@ class WP_REST_Widget_Types_Controller extends WP_REST_Controller {
$widgets[ $widget['id'] ] = $widget;
}
ksort( $widgets );
return $widgets;
}

View File

@ -125,6 +125,22 @@ class WP_Test_REST_Widget_Types_Controller extends WP_Test_REST_Controller_Testc
}
}
/**
* @ticket 53303
*/
public function test_get_items_ordering() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/widget-types' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertGreaterThan( 1, count( $data ) );
$ids = wp_list_pluck( $data, 'id' );
$sorted = $ids;
sort( $sorted );
$this->assertSame( $sorted, $ids );
}
/**
* @ticket 53305
*/