-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add tests for gutenberg_render_layout_support_flag #47719
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -380,4 +380,88 @@ public function data_gutenberg_get_layout_style() { | |
), | ||
); | ||
} | ||
|
||
/** | ||
* Check that gutenberg_render_layout_support_flag() renders the correct classnames on the wrapper. | ||
* | ||
* @dataProvider data_layout_support_flag_renders_classnames_on_wrapper | ||
* | ||
* @covers ::gutenberg_render_layout_support_flag | ||
* | ||
* @param array $args Dataset to test. | ||
* @param string $expected_output The expected output. | ||
*/ | ||
public function test_layout_support_flag_renders_classnames_on_wrapper( $args, $expected_output ) { | ||
$actual_output = gutenberg_render_layout_support_flag( $args['block_content'], $args['block'] ); | ||
$this->assertEquals( $expected_output, $actual_output ); | ||
} | ||
|
||
/** | ||
* Data provider for test_layout_support_flag_renders_classnames_on_wrapper. | ||
* | ||
* @return array | ||
*/ | ||
public function data_layout_support_flag_renders_classnames_on_wrapper() { | ||
return array( | ||
'single wrapper block layout with flow type' => array( | ||
'args' => array( | ||
'block_content' => '<div class="wp-block-group"></div>', | ||
'block' => array( | ||
'blockName' => 'core/group', | ||
'attrs' => array( | ||
'layout' => array( | ||
'type' => 'default', | ||
), | ||
), | ||
'innerBlocks' => array(), | ||
'innerHTML' => '<div class="wp-block-group"></div>', | ||
'innerContent' => array( | ||
'<div class="wp-block-group"></div>', | ||
), | ||
), | ||
), | ||
'expected_output' => '<div class="wp-block-group is-layout-flow"></div>', | ||
), | ||
'single wrapper block layout with constrained type' => array( | ||
'args' => array( | ||
'block_content' => '<div class="wp-block-group"></div>', | ||
'block' => array( | ||
'blockName' => 'core/group', | ||
'attrs' => array( | ||
'layout' => array( | ||
'type' => 'constrained', | ||
), | ||
), | ||
'innerBlocks' => array(), | ||
'innerHTML' => '<div class="wp-block-group"></div>', | ||
'innerContent' => array( | ||
'<div class="wp-block-group"></div>', | ||
), | ||
), | ||
), | ||
'expected_output' => '<div class="wp-block-group is-layout-constrained"></div>', | ||
), | ||
'multiple wrapper block layout with flow type' => array( | ||
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. Nice idea making sure the inner wrapper logic works 👍 |
||
'args' => array( | ||
'block_content' => '<div class="wp-block-group"><div class="wp-block-group__inner-wrapper"></div></div>', | ||
'block' => array( | ||
'blockName' => 'core/group', | ||
'attrs' => array( | ||
'layout' => array( | ||
'type' => 'default', | ||
), | ||
), | ||
'innerBlocks' => array(), | ||
'innerHTML' => '<div class="wp-block-group"><div class="wp-block-group__inner-wrapper"></div></div>', | ||
'innerContent' => array( | ||
'<div class="wp-block-group"><div class="wp-block-group__inner-wrapper">', | ||
' ', | ||
' </div></div>', | ||
), | ||
), | ||
), | ||
'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-wrapper is-layout-flow"></div></div>', | ||
), | ||
); | ||
} | ||
} |
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.
This looks good to me, but I was wondering if there's a code style preference between placing the params in a nested
args
array or moving them one level up to be at the root of the array (and therefore become their own params ontest_layout_support_flag_renders_classnames_on_wrapper
)? So far I haven't been nesting them further in data providers, but it does look like a good way to keep the params contained 👍In short: this was just a comment, not anything that needs changing IMO 🙂
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.
I copied this from the
get_layout_style
tests as it felt like a nice way to structure it! Not sure how widespread one or the other approach is.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.
Ah yes, of course! Let's leave it as is, looks nice to me, too, I'll probably borrow it next time I'm writing a data provider 🙂