-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block Hooks API: Update block-template-utils for first-last child template parts #6867
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
Closed
tjcafferkey
wants to merge
30
commits into
WordPress:trunk
from
tjcafferkey:update/allow-hooked-blocks-first-last-child-into-template-part
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b020b06
Update template utils to accommodate first_child and last_child hooke…
tjcafferkey 6b78fcd
Insert ignoredHookedBlocks postmeta via rest_pre_insert_wp_template_p…
tjcafferkey 1dccc50
Update comment
tjcafferkey 87462d5
Update tests
tjcafferkey 8978b80
Add assertion, change anchor block
ockham d5f6c30
Update tests
tjcafferkey 0ed6e89
Remove duplciate get_post_meta call
tjcafferkey 83040a6
Build correct context for the block hooks API when the post type is a…
tjcafferkey 5e4876c
Test coverage
tjcafferkey 1e3e362
Ensure that for template files _inject_theme_attribute_in_template_pa…
tjcafferkey f4062ad
Update comments
tjcafferkey 6c95919
Remove update_ignored_hooked_blocks_postmeta from rest_pre_insert_wp_…
ockham 0ceb66b
Add extract_serialized_parent_block helper
ockham 5489657
Handle template-part first_child/last_child insertion in inject_ignor…
ockham 46c73e0
Revert changes to update_ignored_hooked_blocks_postmeta
ockham 9fa3ee7
Add note about _make_mock_parsed_block being internal use only
ockham e676f4b
Add test coverage
ockham 560dcce
Revert changes to updateIgnoredHookedBlocksPostMeta test
ockham 58c6689
Clean up post meta
ockham e7db202
Start fixing tests
ockham adacaae
Polish test
ockham b3377b3
Fix other tests
ockham 97d4624
Add ticket numbers
ockham f324f96
Single quotes
ockham 83cfa72
Polish other tests
ockham 1ddf9d3
Add PHPDoc descriptions to _make_mock_parsed_block
ockham 40464ce
Wrap a line
ockham 5df1860
Revert "Wrap a line"
ockham 1517c44
Rewrite to remove _make_mock_parsed_block
ockham b679595
Variable names
ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,20 @@ | |
| * @covers ::_build_block_template_result_from_file | ||
| */ | ||
| class Tests_Block_Templates_BuildBlockTemplateResultFromFile extends WP_Block_Templates_UnitTestCase { | ||
| /** | ||
| * Tear down each test method. | ||
| * | ||
| * @since 6.7.0 | ||
| */ | ||
| public function tear_down() { | ||
| $registry = WP_Block_Type_Registry::get_instance(); | ||
|
|
||
| if ( $registry->is_registered( 'tests/my-block' ) ) { | ||
| $registry->unregister( 'tests/my-block' ); | ||
| } | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 54335 | ||
|
|
@@ -178,4 +192,78 @@ public function test_should_ignore_post_types_property_when_building_template_pa | |
|
|
||
| $this->assertEmpty( $template->post_types ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60506 | ||
| */ | ||
| public function test_should_inject_hooked_block_into_template_part() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/paragraph' => 'after', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $template_part = _build_block_template_result_from_file( | ||
| array( | ||
| 'slug' => 'header', | ||
| 'postTypes' => array( 'post' ), | ||
| 'path' => DIR_TESTDATA . '/templates/template.html', | ||
| ), | ||
| 'wp_template_part' | ||
| ); | ||
| $this->assertStringEndsWith( '<!-- wp:tests/my-block /-->', $template_part->content ); | ||
| } | ||
|
|
||
| /* | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing star. Same for some other unit tests For ex.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thank you! I'll address in a follow-up. |
||
| * @ticket 60506 | ||
| * @ticket 60854 | ||
| */ | ||
| public function test_should_injected_hooked_block_into_template_part_first_child() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/template-part' => 'first_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $template_part = _build_block_template_result_from_file( | ||
| array( | ||
| 'slug' => 'header', | ||
| 'postTypes' => array( 'post' ), | ||
| 'path' => DIR_TESTDATA . '/templates/template.html', | ||
| ), | ||
| 'wp_template_part' | ||
| ); | ||
| $this->assertStringStartsWith( '<!-- wp:tests/my-block /-->', $template_part->content ); | ||
| } | ||
|
|
||
| /* | ||
| * @ticket 60506 | ||
| * @ticket 60854 | ||
| */ | ||
| public function test_should_injected_hooked_block_into_template_part_last_child() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/template-part' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $template_part = _build_block_template_result_from_file( | ||
| array( | ||
| 'slug' => 'header', | ||
| 'postTypes' => array( 'post' ), | ||
| 'path' => DIR_TESTDATA . '/templates/template.html', | ||
| ), | ||
| 'wp_template_part' | ||
| ); | ||
| $this->assertStringEndsWith( '<!-- wp:tests/my-block /-->', $template_part->content ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra star per inline comment formate.