Skip to content
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

Used WP_Query in wp_get_post_autosave instead of raw query #7962

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

narenin
Copy link

@narenin narenin commented Dec 6, 2024

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


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.

Copy link

github-actions bot commented Dec 6, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props narenin, swissspidy, mukesh27, spacedmonkey.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Dec 6, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Thanks for your patch!

It looks good at first glance. Just two things:

  1. While there is some test coverage for this function already via other tests, it would be good to add dedicated tests for this function. Of course they should all pass :)
  2. Let's remove all those inline comments. They don't provide any additional value.

@swissspidy
Copy link
Member

Additional props to @im3dabasia who opened #7965

@swissspidy swissspidy added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Dec 6, 2024
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Dec 6, 2024
Comment on lines 285 to 289
'post_name' => $post_id . '-autosave-v1', // Autosave name.
'posts_per_page' => 1, // Only need the latest autosave.
'orderby' => 'date', // Order by post date (latest first).
'order' => 'DESC', // Descending order for latest.
'fields' => 'ids', // We only need the post ID to fetch the post object.
Copy link
Member

Choose a reason for hiding this comment

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

Don' need the inline comment

Copy link
Author

Choose a reason for hiding this comment

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

@mukeshpanchal27 I have implemented the suggestions.

Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

Requests some review that will fix tests.

src/wp-includes/revision.php Outdated Show resolved Hide resolved
src/wp-includes/revision.php Outdated Show resolved Hide resolved
src/wp-includes/revision.php Show resolved Hide resolved
Comment on lines 302 to 304
$autosave_id = $query->posts[0];

return get_post( $autosave_id );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$autosave_id = $query->posts[0];
return get_post( $autosave_id );
return get_post( $query->posts[0] );

Copy link
Author

Choose a reason for hiding this comment

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

@mukeshpanchal27 Implemented the suggestion, please check.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Overall looks solid to me. Left some nit-pick feedbacks.

/**
* @group post
*/
class Tests_Post_GetPostAutosave extends WP_UnitTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class Tests_Post_GetPostAutosave extends WP_UnitTestCase {
class Tests_Post_wpGetPostAutosave extends WP_UnitTestCase {

Comment on lines 29 to 33
/**
* Ticket #62658
*
* @see https://core.trac.wordpress.org/ticket/62658
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Ticket #62658
*
* @see https://core.trac.wordpress.org/ticket/62658
*/
/**
* Set up before class.
*
* @param WP_UnitTest_Factory $factory Factory.
*/

Comment on lines 42 to 44
/**
* Test when no autosave exists for a post.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Test when no autosave exists for a post.
*/
/**
* Test when no autosave exists for a post.
*
* @ticket 62658
*/

Add @ticket annotation for unit test.

Comment on lines 50 to 52
/**
* Test when an autosave exists for a post.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Test when an autosave exists for a post.
*/
/**
* Test when an autosave exists for a post.
*
* @ticket 62658
*/

Comment on lines 72 to 74
/**
* Test when an autosave exists for a specific user.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Test when an autosave exists for a specific user.
*/
/**
* Test when an autosave exists for a specific user.
*
* @ticket 62658
*/

Copy link
Author

Choose a reason for hiding this comment

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

@mukeshpanchal27 Thanks for the feedback, I have implemented the suggestions.

tests/phpunit/tests/post/wpGetAutoSave.php Outdated Show resolved Hide resolved
tests/phpunit/tests/post/wpGetAutoSave.php Outdated Show resolved Hide resolved
$this->assertInstanceOf( 'WP_Post', $autosave );
$this->assertSame( self::$editor_id, (int) $autosave->post_author, 'Post author does not match.' );
$this->assertSame( $autosave_id, $autosave->ID, 'Autosave ID does not match.' );
}
Copy link
Member

Choose a reason for hiding this comment

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

WP_Query has caching. Can we add a test here, that creates an autosaves, checks result and the creates a two autosave with the same user and gets the new result?

@mukeshpanchal27
Copy link
Member

@narenin take a look pending feedback #7962 (comment) from @spacedmonkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants