-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix class serialization of font-size and colors in dynamic blocks tha…
…t use block supports (#35751)
- Loading branch information
Showing
4 changed files
with
94 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* Test the typography block supports. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class WP_Block_Supports_Colors_Test extends WP_UnitTestCase { | ||
|
||
function test_color_slugs_with_numbers_are_kebab_cased_properly() { | ||
register_block_type( | ||
'test/color-slug-with-numbers', | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'textColor' => array( | ||
'type' => 'string', | ||
), | ||
'backgroundColor' => array( | ||
'type' => 'string', | ||
), | ||
'gradient' => array( | ||
'type' => 'string', | ||
), | ||
), | ||
'supports' => array( | ||
'color' => array( | ||
'text' => true, | ||
'background' => true, | ||
'gradients' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( 'test/color-slug-with-numbers' ); | ||
|
||
$block_atts = array( | ||
'textColor' => 'fg1', | ||
'backgroundColor' => 'bg2', | ||
'gradient' => 'gr3', | ||
); | ||
|
||
$actual = gutenberg_apply_colors_support( $block_type, $block_atts ); | ||
$expected = array( 'class' => 'has-text-color has-fg-1-color has-background has-bg-2-background-color has-background has-gr-3-gradient-background' ); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( 'test/color-slug-with-numbers' ); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
/** | ||
* Test the typography block supports. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class WP_Block_Supports_Typography_Test extends WP_UnitTestCase { | ||
|
||
function test_font_size_slug_with_numbers_is_kebab_cased_properly() { | ||
register_block_type( | ||
'test/font-size-slug-with-numbers', | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'fontSize' => array( | ||
'type' => 'string', | ||
), | ||
), | ||
'supports' => array( | ||
'typography' => array( | ||
'fontSize' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( 'test/font-size-slug-with-numbers' ); | ||
|
||
$block_atts = array( 'fontSize' => 'h1' ); | ||
|
||
$actual = gutenberg_apply_typography_support( $block_type, $block_atts ); | ||
$expected = array( 'class' => 'has-h-1-font-size' ); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( 'test/font-size-slug-with-numbers' ); | ||
} | ||
} |