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

Add tests for gutenberg_render_layout_support_flag #47719

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions phpunit/block-supports/layout-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

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 on test_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 🙂

Copy link
Contributor Author

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.

Copy link
Contributor

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 🙂

'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(
Copy link
Contributor

Choose a reason for hiding this comment

The 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>',
),
);
}
}