Skip to content

Commit

Permalink
require render_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison-Stavlo committed Jun 25, 2020
1 parent ba6a395 commit 7c17c76
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 31 deletions.
6 changes: 3 additions & 3 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ function gutenberg_experimental_apply_classnames_and_styles( $block_content, $bl
return $block_content;
}

// Check what style features the block supports.
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
if ( ! $block_type ) {
// If no render_callback, assume styles have been previously handled.
if ( ! $block_type || ! $block_type->render_callback ) {
return $block_content;
}

// Check what style features the block supports.
$supports = gutenberg_experimental_global_styles_get_supported_styles( $block_type->supports );

$attributes = array();
Expand Down
114 changes: 86 additions & 28 deletions phpunit/class-block-supported-styles-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ private function assert_styles_and_classes_match( $block, $expected_classes, $ex
*/
function test_named_color_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand Down Expand Up @@ -124,10 +125,11 @@ function test_named_color_support() {
*/
function test_custom_color_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand Down Expand Up @@ -160,12 +162,13 @@ function test_custom_color_support() {
*/
function test_named_link_color_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'linkColor' => true,
),
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -190,12 +193,13 @@ function test_named_link_color_support() {
*/
function test_custom_link_color_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'linkColor' => true,
),
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -220,12 +224,13 @@ function test_custom_link_color_support() {
*/
function test_named_gradient_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'gradients' => true,
),
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -250,12 +255,13 @@ function test_named_gradient_support() {
*/
function test_custom_gradient_support() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'gradients' => true,
),
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -280,8 +286,9 @@ function test_custom_gradient_support() {
*/
function test_color_unsupported() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(),
'attributes' => array(),
'supports' => array(),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand Down Expand Up @@ -315,10 +322,11 @@ function test_color_unsupported() {
*/
function test_named_font_size() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalFontSize' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -343,10 +351,11 @@ function test_named_font_size() {
*/
function test_custom_font_size() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalFontSize' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -371,8 +380,9 @@ function test_custom_font_size() {
*/
function test_font_size_unsupported() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(),
'attributes' => array(),
'supports' => array(),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -398,10 +408,11 @@ function test_font_size_unsupported() {
*/
function test_line_height() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalLineHeight' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -426,8 +437,9 @@ function test_line_height() {
*/
function test_line_height_unsupported() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(),
'attributes' => array(),
'supports' => array(),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand All @@ -452,15 +464,16 @@ function test_line_height_unsupported() {
*/
function test_all_supported() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'gradients' => true,
'linkColor' => true,
),
'__experimentalFontSize' => true,
'__experimentalLineHeight' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand Down Expand Up @@ -497,10 +510,11 @@ function test_all_supported() {
*/
function test_one_supported() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'attributes' => array(),
'supports' => array(
'__experimentalFontSize' => true,
),
'render_callback' => true,
);
$this->register_block_type( 'core/example', $block_type_settings );

Expand Down Expand Up @@ -530,4 +544,48 @@ function test_one_supported() {

$this->assert_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}

/**
* Tests there is no change without 'render_callback' in block_type.
*/
function test_render_callback_required() {
$block_type_settings = array(
'attributes' => array(),
'supports' => array(
'__experimentalColor' => array(
'gradients' => true,
'linkColor' => true,
),
'__experimentalFontSize' => true,
'__experimentalLineHeight' => true,
),
);
$this->register_block_type( 'core/example', $block_type_settings );

$block = array(
'blockName' => 'core/example',
'attrs' => array(
'style' => array(
'color' => array(
'text' => '#000',
'background' => '#fff',
'gradient' => 'some-gradient',
'style' => array( 'color' => array( 'link' => '#fff' ) ),
),
'typography' => array(
'lineHeight' => '20',
'fontSize' => '10',
),
),
),
'innerBlock' => array(),
'innerContent' => array(),
'innerHTML' => array(),
);

$expected_classes = 'wp-block-example foo-bar-class';
$expected_styles = 'test:style;';

$this->assert_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
}

0 comments on commit 7c17c76

Please sign in to comment.