#59325 closed enhancement (fixed)
Block Themes: Test that `_build_block_template_result_from_file` injects `theme` attribute
Reported by: | Bernhard Reiter | Owned by: | Bernhard Reiter |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
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.
This will be needed for #59313.
Change History (11)
This ticket was mentioned in PR #5186 on WordPress/wordpress-develop by @Bernhard Reiter.
17 months ago
#1
- Keywords has-patch has-unit-tests added
17 months ago
#2
As for the functionality, these new tests cover the part of the functionality that is going to be refactored as outlined in https://github.com/WordPress/wordpress-develop/pull/5158 to bring support for the new Block Hooks feature. I can confirm that the tests look as intended.
@Bernhard Reiter commented on PR #5186:
17 months ago
#3
@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 😊
@Bernhard Reiter commented on PR #5186:
16 months ago
#6
Thanks all!
Committed to Core in https://core.trac.wordpress.org/changeset/56562/.
This ticket was mentioned in PR #5396 on WordPress/wordpress-develop by @gziolo.
16 months ago
#7
…ile`
Trac ticket: https://core.trac.wordpress.org/ticket/59325
Follow-up to the comment from @costdev in https://github.com/WordPress/wordpress-develop/pull/5186#discussion_r1324147112:
Here's a coverage report which includes existing tests and tests included in this PR.
Everything that this PR intends to cover appears to be covered. 🙂
In terms of the remaining coverage for this function:
- Line 585 isn't hit by the tests that specifically cover this function.
- Two branches aren't covered.
- One branch can be covered by testing with a
postTypes
key in$template_file
and a$template_type
ofwp_template
.- One branch can be covered by ensuring both outcomes of line 572 are met by tests, then testing
$template->title
for the expected result.- There don't appear to be tests specifically for this function that provide a non-default slug in
$template_file
. This means lines 578-581, while _hit_ by the tests, don't appear to have coverage to ensure that$template->title
is retained forwp_template
types with a non-default slug in the$template_file
.As the uncovered parts don't seem to be part of this PR's goals, we can follow up to complete coverage for
_build_block_template_result_from_file()
. I'd also suggest that we start to separate the tests for each function into their own files, completing@ticket
,@covers
, and any other annotations that need to be added. This makes it easier not to get lost amongst the tests.
16 months ago
#8
Thank you for the feedback. I’ll rename and move test cases as suggested and land tomorrow 👍
16 months ago
#9
It would be good to cover these two conditions so there's a complete set of tests in this function's test class.
Do I understand correctly that you mean adding coverage in the same test suite? I'm sure it has coverage in other places, but I agree we can add another test here 👍🏻
I want to wait until #5455 as I will have to rebase this branch and probably remove on or two tests, maybe move some new tests. I can work on the feedback as part of that.
15 months ago
#11
Committed with https://core.trac.wordpress.org/changeset/56983.
It would be good to cover these two conditions so there's a complete set of tests in this function's test class.
I will work on more tests separately covering the filter hooked_block_types
, and I will tackle it as part of that effort.
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
trunk
, and run unit tests (npm run test:php -- --group=block-templates
). Verify that they pass (although they shouldn't) ✅ 👎src/wp-includes/block-template-utils.php
_inject_theme_attribute_in_block_template_content( $template_content );Trac ticket: https://core.trac.wordpress.org/ticket/59325