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

Comment Template Block: Add test coverage for context setting and inner block insertion #4507

Conversation

ockham
Copy link
Contributor

@ockham ockham commented May 25, 2023

Backport of WordPress/gutenberg#50879 and WordPress/gutenberg#50883.

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


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.

@ockham
Copy link
Contributor Author

ockham commented May 25, 2023

Note that the test_rendering_comment_template_sets_comment_id_context test will only pass once a version of @wordpress/block-library is used in Core that includes WordPress/gutenberg#50279.

@ockham ockham force-pushed the add/test-coverage-for-comments-template-block-context branch from af0ffd9 to ddf8439 Compare May 31, 2023 15:20
@ockham
Copy link
Contributor Author

ockham commented May 31, 2023

Added tests from WordPress/gutenberg#50883.

@ockham ockham changed the title Comment Template Block: Add test coverage for context setting Comment Template Block: Add test coverage for context setting and inner block insertion May 31, 2023
@tellthemachines
Copy link
Contributor

Hi 👋
I assume this change is meant for 6.3? If so, could you create a Trac ticket to link this PR please?

@ockham
Copy link
Contributor Author

ockham commented Jun 15, 2023

@tellthemachines Apologies, I still haven't gotten around to do this. Upon second thought, I think I should split the PR in two, one of which we should be able to merge before Beta 1 (when blocks are synced from GB), whereas the other test will only pass after that sync.

I'll try to take care of that splitting, plus filing the required tickets, early next week. (Then again, none of this is super-urgent, so it's not the end of the world if it doesn't go into 6.3.)

@tellthemachines
Copy link
Contributor

Thanks for the update @ockham !

@ockham ockham force-pushed the add/test-coverage-for-comments-template-block-context branch from 9c1457c to c9485df Compare July 6, 2023 09:41
@ockham
Copy link
Contributor Author

ockham commented Jul 6, 2023

Note that the test_rendering_comment_template_sets_comment_id_context test will only pass once a version of @wordpress/block-library is used in Core that includes WordPress/gutenberg#50279.

Rebased to pick up the updated packages and to make tests pass 🤞

Wondering if we should consider including these with 6.3 after all, given https://core.trac.wordpress.org/ticket/58699. (The tests wouldn't have caught that, but they provide some confidence that we don't introduce any regressions when fixing that. This might be a bit more academic here, since the fix has to be made in GB anyway, where those tests are already in place.)

@tellthemachines
Copy link
Contributor

I'm not against adding more test coverage 😄

Is this ready for review then? Asking because it's still in draft mode.

@ockham
Copy link
Contributor Author

ockham commented Jul 13, 2023

I'm not against adding more test coverage 😄

Is this ready for review then? Asking because it's still in draft mode.

Ah yep, I guess it is -- apologies 😅 I guess I wasn't 100% sure if the tests were "minimal" enough (especially test_inner_block_inserted_by_render_block_data_is_retained), but maybe that's for reviewers to decide 😅

@ockham ockham force-pushed the add/test-coverage-for-comments-template-block-context branch from c9485df to 5cc94a3 Compare July 13, 2023 14:50
@ockham ockham marked this pull request as ready for review July 13, 2023 14:50
Copy link

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

These tests are generally looking good to add to me. Just left a question about the remove_filter and add_filter calls for Gutenberg filters. I imagine those can be removed? I couldn't find gutenberg_auto_insert_child_block in the Gutenberg repo, but I might be missing some context there potentially.

tests/phpunit/tests/blocks/renderCommentTemplate.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/renderCommentTemplate.php Outdated Show resolved Hide resolved
@ockham
Copy link
Contributor Author

ockham commented Jul 17, 2023

These tests are generally looking good to add to me. Just left a question about the remove_filter and add_filter calls for Gutenberg filters. I imagine those can be removed? I couldn't find gutenberg_auto_insert_child_block in the Gutenberg repo, but I might be missing some context there potentially.

Ah, great spot! Yep, they can be removed; I'll take care of that. Thank you for flagging 👍 😄

return $inserted_content . $block_content;
};

add_filter( 'render_block', $render_block_callback, 10, 3 );
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to store the callback, just pass it directly here. The test suite cleans up all filters after each test, so no need to call remove_filter()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you mean like inline? Cool, will do 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ockham
Copy link
Contributor Author

ockham commented Jul 18, 2023

Took me a while, but I’ve filed the ticket. I've also addressed everyone's feedback (thank you!)

We're pretty close to RC1, so I'm not sure if folks are comfortable merging this so late in the game. OTOH, it's a test-only change that's supposed to guard against regressions 🤔

@ockham ockham force-pushed the add/test-coverage-for-comments-template-block-context branch from 756caa6 to ec9a7ae Compare July 18, 2023 14:41
@ockham
Copy link
Contributor Author

ockham commented Jul 18, 2023

Added some more coverage in d3e3ffd to cover the scenario fixed by WordPress/gutenberg#52364.

cc/ @dlh01

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Just some nit feedback, but with these and @mukeshpanchal27's suggestions, this looks good to go. Thanks @ockham!

Pre-approving so as not to hold up commit as my internet is tempramental today.

tests/phpunit/tests/blocks/renderCommentTemplate.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/renderCommentTemplate.php Outdated Show resolved Hide resolved
ockham and others added 3 commits July 18, 2023 17:37
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
@ockham
Copy link
Contributor Author

ockham commented Jul 18, 2023

Thanks all! Committed to Core in https://core.trac.wordpress.org/changeset/56262 😊

@ockham ockham closed this Jul 18, 2023
@ockham ockham deleted the add/test-coverage-for-comments-template-block-context branch July 18, 2023 16:08
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.

8 participants