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

Block Themes: Ensure that _build_block_template_result_from_file() injects theme attribute #5186

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Sep 11, 2023

While we have coverage for _inject_theme_attribute_in_block_template_content, those tests only verify that that function does what is supposed to do; there's however no guarantee that _build_block_template_result_from_file uses that function (or whatever other technique) to actually inject the theme attribute (see).

Testing Instructions

  • Apply the following patch first on trunk, and run unit tests (npm run test:php -- --group=block-templates). Verify that they pass (although they shouldn't) ✅ 👎
  • Then, apply the patch on top of this branch, and run unit tests again. Verify that this time, they fail. ❌ 👍
  • Finally, remove the patch (or check CI for this branch): Unit tests should pass ✅ 👍
diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php
index b8538ee3b43e..11d4141aa342 100644
--- a/src/wp-includes/block-template-utils.php
+++ b/src/wp-includes/block-template-utils.php
@@ -565,7 +565,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
 	$template                 = new WP_Block_Template();
 	$template->id             = $theme . '//' . $template_file['slug'];
 	$template->theme          = $theme;
-	$template->content        = _inject_theme_attribute_in_block_template_content( $template_content );
+	$template->content        = $template_content;
 	$template->slug           = $template_file['slug'];
 	$template->source         = 'theme';
 	$template->type           = $template_type;

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


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 ockham self-assigned this Sep 11, 2023
@ockham ockham marked this pull request as ready for review September 11, 2023 16:01
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.

Thanks for the PR @ockham! I've left some feedback for consistency with test standards and conventions. 🙂

References:

tests/phpunit/tests/block-template-utils.php Show resolved Hide resolved
tests/phpunit/tests/block-template-utils.php Show resolved Hide resolved
tests/phpunit/tests/block-template-utils.php Outdated Show resolved Hide resolved
tests/phpunit/tests/block-template-utils.php Outdated Show resolved Hide resolved
tests/phpunit/tests/block-template-utils.php Show resolved Hide resolved
@ockham ockham requested a review from gziolo September 11, 2023 16:56
@gziolo
Copy link
Member

gziolo commented Sep 12, 2023

As for the functionality, these new tests cover the part of the functionality that is going to be refactored as outlined in #5158 to bring support for the new Block Hooks feature. I can confirm that the tests look as intended.

@ockham
Copy link
Contributor Author

ockham commented Sep 12, 2023

@costdev Thank you for your feedback! I believe I've addressed it all 😊

Would you mind giving it another look when you have a moment? I'd love to land this soon as it's only the first step for Block Hooks to land in 6.4 😊

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Let's get this in, as all the feedback seems to be addressed. Let's ensure to follow up with the code coverage part seperately.

@ockham
Copy link
Contributor Author

ockham commented Sep 13, 2023

Thanks all!

Committed to Core in https://core.trac.wordpress.org/changeset/56562/.

@ockham ockham closed this Sep 13, 2023
@ockham ockham deleted the add/test-coverage-for-build-block-template-result-from-file-theme-data-attribute branch September 13, 2023 12:04
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.

5 participants