Skip to content

Rest API: add /revisions endpoint for global styles - #4606

Closed
ramonjd wants to merge 21 commits into
WordPress:trunkfrom
ramonjd:add/rest-api-global-revisions-controller
Closed

ramonjd wants to merge 21 commits into
WordPress:trunkfrom
ramonjd:add/rest-api-global-revisions-controller

Conversation

@ramonjd

@ramonjd ramonjd commented Jun 13, 2023

Copy link
Copy Markdown
Member

The following Global Revisions UI was added to Gutenberg in:

To support this, an endpoint (/wp/v2/global-styles/revisions) that returns revisions for the global styles custom post was added and updated in:

This PR adds the endpoint to Core and adds tests.

Trac ticket: https://core.trac.wordpress.org/ticket/58524

Testing

To test the endpoint in the site editor, fire up this branch and head over to the site editor.

In your browser's console, switch to the network tab and run the following :

await wp.apiFetch( { url: `/index.php?rest_route=%2Fwp%2Fv2%2Fglobal-styles%2F${ wp.data.select('core').__experimentalGetCurrentGlobalStylesId() }%2Frevisions&_locale=user` } );

npm run test:php -- --filter WP_REST_Global_Styles_Revisions_Controller_Test


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@ramonjd
ramonjd force-pushed the add/rest-api-global-revisions-controller branch from 268d816 to 82b6ddd Compare June 13, 2023 21:35

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ramonjd, Can you add ticket number in unit tests?

* @doesNotPerformAssertions
*/
public function test_context_param() {
// Controller does not use get_context_param().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller does have context set, so this should get tests.

@ramonjd ramonjd Jun 23, 2023 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that.

I was looking at how other tests implement test_context_param() (example), and they're testing the data in $data['endpoints'] after an OPTIONS call.

This controller doesn't have any other endpoint, e.g., WP_REST_Server::CREATABLE and so I'm not sure how to test it. $data['endpoints'] doesn't have any testable data. Any tips?

I'll add another get_items test to check that the correct fields are returned however.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test test_get_item_embed_context to check the difference when sending context as an arg in the GET request

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nit picks, really.

@ramonjd
ramonjd force-pushed the add/rest-api-global-revisions-controller branch 2 times, most recently from 92207a8 to de82ac9 Compare June 23, 2023 05:52
@ramonjd

ramonjd commented Jun 23, 2023

Copy link
Copy Markdown
Member Author

Thank @TimothyBJacobs @spacedmonkey and @peterwilsoncc for helping me make this patch better.

I think I've addressed all of the feedback, (except for the context test) at least I think so. Please let me know where it can be improved.

@ramonjd
ramonjd force-pushed the add/rest-api-global-revisions-controller branch from d97362a to 41a765e Compare June 23, 2023 07:05
@ramonjd
ramonjd force-pushed the add/rest-api-global-revisions-controller branch from 1ec3540 to f9bb652 Compare June 26, 2023 23:37
@ramonjd
ramonjd requested a review from spacedmonkey June 26, 2023 23:55

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits but otherwise looks good.

@spacedmonkey spacedmonkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good. The unit tests could do with @covers.

@tellthemachines

Copy link
Copy Markdown
Contributor

committed in r56082 / c345180.

ramonjd added a commit to ramonjd/wordpress-develop that referenced this pull request Jun 29, 2023
Formatting and test annotations to include @Covers
@ramonjd

ramonjd commented Jun 29, 2023

Copy link
Copy Markdown
Member Author

The unit tests could do with @Covers.

Thanks! PR for that here: #4750

ramonjd added a commit to WordPress/gutenberg that referenced this pull request Jun 29, 2023
ramonjd added a commit to WordPress/gutenberg that referenced this pull request Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

6 participants