-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve unit test coverage for REST API menus endpoints. #36177
Conversation
@@ -479,21 +479,23 @@ protected function prepare_item_for_database( $request ) { | |||
} | |||
} | |||
|
|||
$error = new WP_Error(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, but makes debugging easier, as you can see multiple errors in REST API response.
@@ -324,7 +324,7 @@ public function update_item( $request ) { | |||
* Deletes a single menu item. | |||
* | |||
* @param WP_REST_Request $request Full details about the request. | |||
* @return true|WP_Error True on success, or WP_Error object on failure. | |||
* @return WP_REST_Response|WP_Error True on success, or WP_Error object on failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return type was wrong.
if ( 'block' === $prepared_nav_item['menu-item-type'] ) { | ||
if ( empty( $prepared_nav_item['menu-item-content'] ) ) { | ||
return new WP_Error( 'rest_content_required', __( 'Content required if menu item of type block.', 'gutenberg' ), array( 'status' => 400 ) ); | ||
if ( 'block' === $prepared_nav_item['menu-item-type'] && empty( $prepared_nav_item['menu-item-content'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for two if statements here.
$links['https://api.w.org/object'][] = array( | ||
'href' => rest_url( $path ), | ||
'post_type' => $menu_item->type, | ||
$key => $type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was incorrect, this is a bug fix.
} | ||
|
||
if ( $path ) { | ||
if ( $path && $type ) { | ||
$links['https://api.w.org/object'][] = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyBJacobs did you want to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's change the type to menu-item-object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in dc23cdc
Looks good, thanks. Yeah let's just adjust that menu item link relation. |
Description
Improve unit test coverage for REST API menus endpoints.
Bug fixes and tweaks to code to improve code.
Final tweaks, before core merge.
Fixes #34992