-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding skip serialization tests
- Loading branch information
Showing
4 changed files
with
445 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
/** | ||
* Test the border block supports. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class WP_Block_Supports_Border_Test extends WP_UnitTestCase { | ||
|
||
function test_border_color_slug_with_numbers_is_kebab_cased_properly() { | ||
$block_name = 'test/border-color-slug-with-numbers-is-kebab-cased-properly'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'borderColor' => array( | ||
'type' => 'string', | ||
), | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'__experimentalBorder' => array( | ||
'color' => true, | ||
'radius' => true, | ||
'width' => true, | ||
'style' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'borderColor' => 'red', | ||
'style' => array( | ||
'border' => array( | ||
'radius' => '10px', | ||
'width' => '1px', | ||
'style' => 'dashed', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_border_support( $block_type, $block_atts ); | ||
$expected = array( | ||
'class' => 'has-border-color has-red-border-color', | ||
'style' => 'border-radius: 10px; border-style: dashed; border-width: 1px;', | ||
); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
|
||
function test_border_with_skipped_serialization_block_supports() { | ||
$block_name = 'test/border-with-skipped-serialization-block-supports'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'__experimentalBorder' => array( | ||
'color' => true, | ||
'radius' => true, | ||
'width' => true, | ||
'style' => true, | ||
'__experimentalSkipSerialization' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'style' => array( | ||
'border' => array( | ||
'color' => '#eeeeee', | ||
'width' => '1px', | ||
'style' => 'dotted', | ||
'radius' => '10px', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_border_support( $block_type, $block_atts ); | ||
$expected = array(); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
|
||
function test_radius_with_individual_skipped_serialization_block_supports() { | ||
$block_name = 'test/radius-with-individual-skipped-serialization-block-supports'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'__experimentalBorder' => array( | ||
'color' => true, | ||
'radius' => true, | ||
'width' => true, | ||
'style' => true, | ||
'__experimentalSkipSerialization' => array( 'radius', 'color' ), | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'style' => array( | ||
'border' => array( | ||
'color' => '#eeeeee', | ||
'width' => '1px', | ||
'style' => 'dotted', | ||
'radius' => '10px', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_border_support( $block_type, $block_atts ); | ||
$expected = array( | ||
'style' => 'border-style: dotted; border-width: 1px;', | ||
); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
} |
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,148 @@ | ||
<?php | ||
|
||
/** | ||
* Test the spacing block supports. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class WP_Block_Supports_Spacing_Test extends WP_UnitTestCase { | ||
|
||
function test_spacing_style_is_applied() { | ||
$block_name = 'test/spacing-style-is-applied'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'spacing' => array( | ||
'margin' => true, | ||
'padding' => true, | ||
'blockGap' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'style' => array( | ||
'spacing' => array( | ||
'margin' => array( | ||
'top' => '1px', | ||
'right' => '2px', | ||
'bottom' => '3px', | ||
'left' => '4px', | ||
), | ||
'padding' => '111px', | ||
'blockGap' => '2em', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_spacing_support( $block_type, $block_atts ); | ||
$expected = array( | ||
'style' => 'padding: 111px; margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;', | ||
); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
|
||
function test_spacing_with_skipped_serialization_block_supports() { | ||
$block_name = 'test/spacing-with-skipped-serialization-block-supports'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'spacing' => array( | ||
'margin' => true, | ||
'padding' => true, | ||
'blockGap' => true, | ||
'__experimentalSkipSerialization' => true, | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'style' => array( | ||
'spacing' => array( | ||
'margin' => array( | ||
'top' => '1px', | ||
'right' => '2px', | ||
'bottom' => '3px', | ||
'left' => '4px', | ||
), | ||
'padding' => '111px', | ||
'blockGap' => '2em', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_spacing_support( $block_type, $block_atts ); | ||
$expected = array(); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
|
||
function test_margin_with_individual_skipped_serialization_block_supports() { | ||
$block_name = 'test/margin-with-individual-skipped-serialization-block-supports'; | ||
register_block_type( | ||
$block_name, | ||
array( | ||
'api_version' => 2, | ||
'attributes' => array( | ||
'style' => array( | ||
'type' => 'object', | ||
), | ||
), | ||
'supports' => array( | ||
'spacing' => array( | ||
'margin' => true, | ||
'padding' => true, | ||
'blockGap' => true, | ||
'__experimentalSkipSerialization' => array( 'margin' ), | ||
), | ||
), | ||
) | ||
); | ||
$registry = WP_Block_Type_Registry::get_instance(); | ||
$block_type = $registry->get_registered( $block_name ); | ||
$block_atts = array( | ||
'style' => array( | ||
'spacing' => array( | ||
'padding' => array( | ||
'top' => '1px', | ||
'right' => '2px', | ||
'bottom' => '3px', | ||
'left' => '4px', | ||
), | ||
'margin' => '111px', | ||
'blockGap' => '2em', | ||
), | ||
), | ||
); | ||
|
||
$actual = gutenberg_apply_spacing_support( $block_type, $block_atts ); | ||
$expected = array( | ||
'style' => 'padding-top: 1px; padding-right: 2px; padding-bottom: 3px; padding-left: 4px;', | ||
); | ||
|
||
$this->assertSame( $expected, $actual ); | ||
unregister_block_type( $block_name ); | ||
} | ||
} |
Oops, something went wrong.