mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Backport Layout block support refactor part 2 #3254
Closed
andrewserong
wants to merge
14
commits into
WordPress:trunk
from
andrewserong:try/backport-layout-block-support-refactor-part-2
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7761f11
Backport Layou block support refactor part 2
andrewserong 7a1b5d4
Add tests
andrewserong a7904b4
Update test fixtures with new classnames
andrewserong c5dd3dc
Fix Layout tests
andrewserong 145a9c2
Add code quality updates based on feedback
andrewserong 0007932
Fix whitespace linting issue
andrewserong dcebfae
Try to fix odd linting issue
andrewserong 8fe0766
Revert prior change to linting
andrewserong ef94265
Re-fix linting
andrewserong 2a6a882
Split call to wp_get_layout_style onto multiple lines
andrewserong d64d61d
Empty commit to restart CI
andrewserong 0099959
`return` mention improvement
audrasjb ad32baa
Update wp_get_layout_style() DocBlock
hellofromtonya 5371947
Move tests to separate file
hellofromtonya 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
2 changes: 1 addition & 1 deletion
2
tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html
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
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
2 changes: 1 addition & 1 deletion
2
tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html
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
253 changes: 253 additions & 0 deletions
253
tests/phpunit/tests/block-supports/wpGetLayoutStyle.php
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 |
---|---|---|
@@ -0,0 +1,253 @@ | ||
<?php | ||
|
||
/** | ||
* @group block-supports | ||
* @covers ::wp_get_layout_style | ||
*/ | ||
class Tests_Block_Supports_WpGetLayoutStyle extends WP_UnitTestCase { | ||
const ARGS_DEFAULTS = array( | ||
'selector' => null, | ||
'layout' => null, | ||
'has_block_gap_support' => false, | ||
'gap_value' => null, | ||
'should_skip_gap_serialization' => false, | ||
'fallback_gap_value' => '0.5em', | ||
'block_spacing' => null, | ||
); | ||
|
||
/** | ||
* @dataProvider data_wp_get_layout_style | ||
* @ticket 56467 | ||
* | ||
* @param array $args Dataset to test. | ||
* @param string $expected_output The expected output. | ||
*/ | ||
public function test_wp_get_layout_style( array $args, $expected_output ) { | ||
$args = array_merge( static::ARGS_DEFAULTS, $args ); | ||
$layout_styles = wp_get_layout_style( | ||
$args['selector'], | ||
$args['layout'], | ||
$args['has_block_gap_support'], | ||
$args['gap_value'], | ||
$args['should_skip_gap_serialization'], | ||
$args['fallback_gap_value'], | ||
$args['block_spacing'] | ||
); | ||
|
||
$this->assertSame( $expected_output, $layout_styles ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array | ||
*/ | ||
public function data_wp_get_layout_style() { | ||
return array( | ||
'no args should return empty value' => array( | ||
'args' => array(), | ||
'expected_output' => '', | ||
), | ||
'nulled args should return empty value' => array( | ||
'args' => array( | ||
'selector' => null, | ||
'layout' => null, | ||
'has_block_gap_support' => null, | ||
'gap_value' => null, | ||
'should_skip_gap_serialization' => null, | ||
'fallback_gap_value' => null, | ||
'block_spacing' => null, | ||
), | ||
'expected_output' => '', | ||
), | ||
'only selector should return empty value' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
), | ||
'expected_output' => '', | ||
), | ||
'default layout and block gap support' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'has_block_gap_support' => true, | ||
'gap_value' => '1em', | ||
), | ||
'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:1em;margin-block-end:0;}', | ||
), | ||
'skip serialization should return empty value' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'has_block_gap_support' => true, | ||
'gap_value' => '1em', | ||
'should_skip_gap_serialization' => true, | ||
), | ||
'expected_output' => '', | ||
), | ||
'default layout and axial block gap support' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'has_block_gap_support' => true, | ||
'gap_value' => array( 'top' => '1em' ), | ||
), | ||
'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:1em;margin-block-end:0;}', | ||
), | ||
'constrained layout with sizes' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'constrained', | ||
'contentSize' => '800px', | ||
'wideSize' => '1200px', | ||
), | ||
), | ||
'expected_output' => '.wp-layout > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width:800px;margin-left:auto !important;margin-right:auto !important;}.wp-layout > .alignwide{max-width:1200px;}.wp-layout .alignfull{max-width:none;}', | ||
), | ||
'constrained layout with sizes and block spacing' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'constrained', | ||
'contentSize' => '800px', | ||
'wideSize' => '1200px', | ||
), | ||
'block_spacing' => array( | ||
'padding' => array( | ||
'left' => '20px', | ||
'right' => '10px', | ||
), | ||
), | ||
), | ||
'expected_output' => '.wp-layout > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width:800px;margin-left:auto !important;margin-right:auto !important;}.wp-layout > .alignwide{max-width:1200px;}.wp-layout .alignfull{max-width:none;}.wp-layout > .alignfull{margin-right:calc(10px * -1);margin-left:calc(20px * -1);}', | ||
), | ||
'constrained layout with block gap support' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'constrained', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => '2.5rem', | ||
), | ||
'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:2.5rem;margin-block-end:0;}', | ||
), | ||
'constrained layout with axial block gap support' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'constrained', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => array( 'top' => '2.5rem' ), | ||
), | ||
'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:2.5rem;margin-block-end:0;}', | ||
), | ||
'constrained layout with block gap support and spacing preset' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'constrained', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => 'var:preset|spacing|50', | ||
), | ||
'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:var(--wp--preset--spacing--50);margin-block-end:0;}', | ||
), | ||
'flex layout with no args should return empty value' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
), | ||
), | ||
'expected_output' => '', | ||
), | ||
'horizontal flex layout should return empty value' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'horizontal', | ||
), | ||
), | ||
'expected_output' => '', | ||
), | ||
'flex layout with properties' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'horizontal', | ||
'flexWrap' => 'nowrap', | ||
'justifyContent' => 'left', | ||
'verticalAlignment' => 'bottom', | ||
), | ||
), | ||
'expected_output' => '.wp-layout{flex-wrap:nowrap;justify-content:flex-start;align-items:flex-end;}', | ||
), | ||
'flex layout with properties and block gap' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'horizontal', | ||
'flexWrap' => 'nowrap', | ||
'justifyContent' => 'left', | ||
'verticalAlignment' => 'bottom', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => '29px', | ||
), | ||
'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:29px;justify-content:flex-start;align-items:flex-end;}', | ||
), | ||
'flex layout with properties and axial block gap' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'horizontal', | ||
'flexWrap' => 'nowrap', | ||
'justifyContent' => 'left', | ||
'verticalAlignment' => 'bottom', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => array( | ||
'top' => '1px', | ||
'left' => '2px', | ||
), | ||
), | ||
'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:1px 2px;justify-content:flex-start;align-items:flex-end;}', | ||
), | ||
'flex layout with properties and axial block gap using spacing preset' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'horizontal', | ||
'flexWrap' => 'nowrap', | ||
'justifyContent' => 'left', | ||
'verticalAlignment' => 'bottom', | ||
), | ||
'has_block_gap_support' => true, | ||
'gap_value' => array( | ||
'left' => 'var:preset|spacing|40', | ||
), | ||
'fallback_gap_value' => '11px', | ||
), | ||
'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:11px var(--wp--preset--spacing--40);justify-content:flex-start;align-items:flex-end;}', | ||
), | ||
'vertical flex layout with properties' => array( | ||
'args' => array( | ||
'selector' => '.wp-layout', | ||
'layout' => array( | ||
'type' => 'flex', | ||
'orientation' => 'vertical', | ||
'flexWrap' => 'nowrap', | ||
'justifyContent' => 'left', | ||
'verticalAlignment' => 'bottom', | ||
), | ||
), | ||
'expected_output' => '.wp-layout{flex-wrap:nowrap;flex-direction:column;align-items:flex-start;}', | ||
), | ||
); | ||
} | ||
} |
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.
Does this keep
wp-container-1
because it has non-default flex settings?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.
Yes, columns set
nowrap
so it has a non-default setting from the perspective of the flex Layout type. Thanks for double-checking!