mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Introduce minimum height dimensions block support.
This changeset adds the new dimension feature's PHP code for supporting minimum height in the block editor inspector and in global styles. Minimum height is quite useful for defining the minimum vertical dimensions of a block, while allowing it to expand beyond that size. In this changeset: * Adds support in `theme.json`. * Adds support in the style engine. * Adds support in `wp_apply_dimensions_support()`. * Renames the setting from `'__experimentalDimensions'` to `dimensions` in `wp_register_dimensions_support()`. * Adds PHPUnit tests. Is renaming `'__experimentalDimensions'` a backwards-compatibility (BC) break? Though the setting has been in the code since 5.9.0, it was never wired to anything, ie it did not expose any controls or styles. Notice in `wp_register_dimensions_support()` and `wp_apply_dimensions_support()` prior to this changeset, there are inline comments as placeholders for height and width support, but no code. If a developer opted in to use it, it had no effect. A search in wp.org's plugin and themes repo showed no instances of this experimental setting. Given there was no functionality attached to it (until this changeset), no change in behavior or effect from removing it, and no usage found in the plugins and themes repository, it does appear to be a BC break. References: * [WordPress/gutenberg#45300 Gutenberg PR 45300] * [WordPress/gutenberg#45334 Gutenberg PR 45334] Follow-up to [53076], [52069]. Props andrewserong, aaronrobertshaw , costdev, hellofromTonya, isabel_brison, joen, paaljoachim, mukesh27, ntsekouras, oandregal, ramonopoly. Fixes #57582. git-svn-id: https://develop.svn.wordpress.org/trunk@55175 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
8604838
commit f3b858c
Showing
6 changed files
with
168 additions
and
8 deletions.
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
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
103 changes: 103 additions & 0 deletions
103
tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.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,103 @@ | ||
<?php | ||
|
||
/** | ||
* @group block-supports | ||
* | ||
* @covers ::wp_apply_dimensions_support | ||
*/ | ||
class Tests_Block_Supports_WpApplyDimensionsSupport extends WP_UnitTestCase { | ||
/** | ||
* @var string|null | ||
*/ | ||
private $test_block_name; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
$this->test_block_name = null; | ||
} | ||
|
||
public function tear_down() { | ||
unregister_block_type( $this->test_block_name ); | ||
$this->test_block_name = null; | ||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Tests that minimum height block support works as expected. | ||
* | ||
* @ticket 57582 | ||
* | ||
* @covers ::wp_apply_dimensions_support | ||
* | ||
* @dataProvider data_minimum_height_block_support | ||
* | ||
* @param string $block_name The test block name to register. | ||
* @param mixed $dimensions The dimensions block support settings. | ||
* @param mixed $expected The expected results. | ||
*/ | ||
public function test_minimum_height_block_support( $block_name, $dimensions, $expected ) { | ||
$this->test_block_name = $block_name; | ||
register_block_type( | ||
$this->test_block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'dimensions' => $dimensions, | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $this->test_block_name ); | ||
$block_attrs = array( | ||
'style' => array( | ||
'dimensions' => array( | ||
'minHeight' => '50vh', | ||
), | ||
), | ||
); | ||
|
||
$actual = wp_apply_dimensions_support( $block_type, $block_attrs ); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array | ||
*/ | ||
public function data_minimum_height_block_support() { | ||
return array( | ||
'style is applied' => array( | ||
'block_name' => 'test/dimensions-block-supports', | ||
'dimensions' => array( | ||
'minHeight' => true, | ||
), | ||
'expected' => array( | ||
'style' => 'min-height:50vh;', | ||
), | ||
), | ||
'style output is skipped when serialization is skipped' => array( | ||
'block_name' => 'test/dimensions-with-skipped-serialization-block-supports', | ||
'dimensions' => array( | ||
'minHeight' => true, | ||
'__experimentalSkipSerialization' => true, | ||
), | ||
'expected' => array(), | ||
), | ||
'style output is skipped when individual feature serialization is skipped' => array( | ||
'block_name' => 'test/min-height-with-individual-skipped-serialization-block-supports', | ||
'dimensions' => array( | ||
'minHeight' => true, | ||
'__experimentalSkipSerialization' => array( 'minHeight' ), | ||
), | ||
'expected' => array(), | ||
), | ||
); | ||
} | ||
} |
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