From 52cf528997f57a00a7727125e5c932644af58cc6 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 17 Aug 2020 13:30:24 +0100 Subject: [PATCH] Add generated block classname to dynamic blocks (#24546) --- lib/block-supports/generated-classname.php | 53 +++++++++++++ lib/block-supports/index.php | 1 + lib/load.php | 1 + packages/block-library/src/archives/index.php | 2 +- packages/block-library/src/calendar/index.php | 3 +- .../block-library/src/categories/index.php | 2 +- .../src/latest-comments/index.php | 16 ++-- .../block-library/src/latest-posts/index.php | 2 +- .../src/navigation-link/index.php | 1 - .../block-library/src/navigation/index.php | 1 - .../block-library/src/post-author/index.php | 1 - .../src/post-comments-count/index.php | 4 +- .../src/post-comments-form/index.php | 4 +- .../block-library/src/post-comments/index.php | 4 +- .../block-library/src/post-date/index.php | 4 +- .../block-library/src/post-excerpt/index.php | 4 +- .../block-library/src/post-tags/index.php | 4 +- .../block-library/src/post-title/index.php | 4 +- packages/block-library/src/rss/index.php | 8 +- packages/block-library/src/search/index.php | 5 +- .../block-library/src/site-logo/index.php | 9 ++- .../block-library/src/site-tagline/index.php | 4 +- .../block-library/src/site-title/index.php | 4 +- .../block-library/src/tag-cloud/index.php | 7 +- .../block-library/src/template-part/index.php | 2 +- phpunit/class-block-supported-styles-test.php | 77 +++++++++++++------ 26 files changed, 150 insertions(+), 77 deletions(-) create mode 100644 lib/block-supports/generated-classname.php diff --git a/lib/block-supports/generated-classname.php b/lib/block-supports/generated-classname.php new file mode 100644 index 00000000000000..4b7044beb2f656 --- /dev/null +++ b/lib/block-supports/generated-classname.php @@ -0,0 +1,53 @@ +supports, array( 'className' ), true ); + if ( $has_generated_classname_support ) { + $block_classname = gutenberg_get_block_default_classname( $block_type->name ); + + if ( $block_classname ) { + $attributes['css_classes'][] = $block_classname; + } + } + + return $attributes; +} diff --git a/lib/block-supports/index.php b/lib/block-supports/index.php index 4b0ad77d8b6d13..958197abf4f009 100644 --- a/lib/block-supports/index.php +++ b/lib/block-supports/index.php @@ -42,6 +42,7 @@ function gutenberg_apply_block_supports( $block_content, $block ) { } $attributes = array(); + $attributes = gutenberg_apply_generated_classname_support( $attributes, $block['attrs'], $block_type ); $attributes = gutenberg_apply_colors_support( $attributes, $block['attrs'], $block_type ); $attributes = gutenberg_apply_typography_support( $attributes, $block['attrs'], $block_type ); $attributes = gutenberg_apply_alignment_support( $attributes, $block['attrs'], $block_type ); diff --git a/lib/load.php b/lib/load.php index ec7613b0270823..f93b7eec81732f 100644 --- a/lib/load.php +++ b/lib/load.php @@ -117,3 +117,4 @@ function gutenberg_is_experiment_enabled( $name ) { require dirname( __FILE__ ) . '/block-supports/colors.php'; require dirname( __FILE__ ) . '/block-supports/typography.php'; require dirname( __FILE__ ) . '/block-supports/custom-classname.php'; +require dirname( __FILE__ ) . '/block-supports/generated-classname.php'; diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 7fb3cf8968b577..d75859529ee084 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -17,7 +17,7 @@ function render_block_core_archives( $attributes ) { $show_post_count = ! empty( $attributes['showPostCounts'] ); - $class = 'wp-block-archives'; + $class = ''; if ( ! empty( $attributes['displayAsDropdown'] ) ) { diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 41d18c010ab1c0..41968b4099a0c3 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -32,8 +32,7 @@ function render_block_core_calendar( $attributes ) { } $output = sprintf( - '
%2$s
', - esc_attr( 'wp-block-calendar' ), + '
%1$s
', get_calendar( true, false ) ); diff --git a/packages/block-library/src/categories/index.php b/packages/block-library/src/categories/index.php index 4880ff56434094..4210315dc148a2 100644 --- a/packages/block-library/src/categories/index.php +++ b/packages/block-library/src/categories/index.php @@ -41,7 +41,7 @@ function render_block_core_categories( $attributes ) { $type = 'list'; } - $class = "wp-block-categories wp-block-categories-{$type}"; + $class = "wp-block-categories-{$type}"; return sprintf( $wrapper_markup, diff --git a/packages/block-library/src/latest-comments/index.php b/packages/block-library/src/latest-comments/index.php index cf5b62aff3ff3a..448677066cfbf6 100644 --- a/packages/block-library/src/latest-comments/index.php +++ b/packages/block-library/src/latest-comments/index.php @@ -116,28 +116,28 @@ function render_block_core_latest_comments( $attributes = array() ) { } } - $class = 'wp-block-latest-comments'; + $classnames = array(); if ( $attributes['displayAvatar'] ) { - $class .= ' has-avatars'; + $classnames[] = 'has-avatars'; } if ( $attributes['displayDate'] ) { - $class .= ' has-dates'; + $classnames[] = 'has-dates'; } if ( $attributes['displayExcerpt'] ) { - $class .= ' has-excerpts'; + $classnames[] = 'has-excerpts'; } if ( empty( $comments ) ) { - $class .= ' no-comments'; + $classnames[] = 'no-comments'; } - $classnames = esc_attr( $class ); + $class = esc_attr( implode( ' ', $classnames ) ); return ! empty( $comments ) ? sprintf( '
    %2$s
', - $classnames, + $class, $list_items_markup ) : sprintf( '
%2$s
', - $classnames, + $class, __( 'No comments to show.' ) ); } diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index fc900fbacf22b7..6aedf67c335db3 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -144,7 +144,7 @@ function render_block_core_latest_posts( $attributes ) { remove_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 ); - $class = 'wp-block-latest-posts wp-block-latest-posts__list'; + $class = 'wp-block-latest-posts__list'; if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) { $class .= ' is-grid'; diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index e685f1b3aad109..ae28e421848586 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -115,7 +115,6 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { $colors['css_classes'], $font_sizes['css_classes'] ); - $classes[] = 'wp-block-navigation-link'; $style_attribute = ( $colors['inline_styles'] || $font_sizes['inline_styles'] ); $css_classes = trim( implode( ' ', $classes ) ); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 4f763e70180bc9..1db0297c23fd82 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -130,7 +130,6 @@ function render_block_core_navigation( $attributes, $content, $block ) { $classes = array_merge( $colors['css_classes'], $font_sizes['css_classes'], - array( 'wp-block-navigation' ), ( isset( $attributes['orientation'] ) && 'vertical' === $attributes['orientation'] ) ? array( 'is-vertical' ) : array(), isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array() ); diff --git a/packages/block-library/src/post-author/index.php b/packages/block-library/src/post-author/index.php index 87cf432a09e5d2..e04ed2c7dfff33 100644 --- a/packages/block-library/src/post-author/index.php +++ b/packages/block-library/src/post-author/index.php @@ -30,7 +30,6 @@ function render_block_core_post_author( $attributes, $content, $block ) { $byline = ! empty( $attributes['byline'] ) ? $attributes['byline'] : false; $classes = array_merge( - array( 'wp-block-post-author' ), isset( $attributes['className'] ) ? array( $attributes['className'] ) : array(), isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array(), isset( $attributes['textAlign'] ) ? array( 'has-text-align-' . $attributes['textAlign'] ) : array() diff --git a/packages/block-library/src/post-comments-count/index.php b/packages/block-library/src/post-comments-count/index.php index 9cd0ef6991c765..51076970a7034c 100644 --- a/packages/block-library/src/post-comments-count/index.php +++ b/packages/block-library/src/post-comments-count/index.php @@ -18,9 +18,9 @@ function render_block_core_post_comments_count( $attributes, $content, $block ) return ''; } - $classes = 'wp-block-post-comments-count'; + $classes = ''; if ( isset( $attributes['textAlign'] ) ) { - $classes .= ' has-text-align-' . $attributes['textAlign']; + $classes .= 'has-text-align-' . $attributes['textAlign']; } return sprintf( diff --git a/packages/block-library/src/post-comments-form/index.php b/packages/block-library/src/post-comments-form/index.php index 70e61d0a3df736..ab9ba3fef0e899 100644 --- a/packages/block-library/src/post-comments-form/index.php +++ b/packages/block-library/src/post-comments-form/index.php @@ -18,9 +18,9 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) { return ''; } - $classes = 'wp-block-post-comments-form'; + $classes = ''; if ( isset( $attributes['textAlign'] ) ) { - $classes .= ' has-text-align-' . $attributes['textAlign']; + $classes .= 'has-text-align-' . $attributes['textAlign']; } ob_start(); diff --git a/packages/block-library/src/post-comments/index.php b/packages/block-library/src/post-comments/index.php index e68e139e2dfddb..6456e0f98dfa85 100644 --- a/packages/block-library/src/post-comments/index.php +++ b/packages/block-library/src/post-comments/index.php @@ -31,9 +31,9 @@ function render_block_core_post_comments( $attributes, $content, $block ) { comments_template(); $post = $post_before; - $classes = 'wp-block-post-comments'; + $classes = ''; if ( isset( $attributes['textAlign'] ) ) { - $classes .= ' has-text-align-' . $attributes['textAlign']; + $classes .= 'has-text-align-' . $attributes['textAlign']; } $output = sprintf( '
', esc_attr( $classes ) ) . ob_get_clean() . '
'; diff --git a/packages/block-library/src/post-date/index.php b/packages/block-library/src/post-date/index.php index 60500da9e0aeb6..8413734d73ecf3 100644 --- a/packages/block-library/src/post-date/index.php +++ b/packages/block-library/src/post-date/index.php @@ -18,11 +18,11 @@ function render_block_core_post_date( $attributes, $content, $block ) { return ''; } - $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}"; + $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; return sprintf( '
', - 'wp-block-post-date' . esc_attr( $align_class_name ), + esc_attr( $align_class_name ), get_the_date( 'c', $block->context['postId'] ), get_the_date( isset( $attributes['format'] ) ? $attributes['format'] : '', $block->context['postId'] ) ); diff --git a/packages/block-library/src/post-excerpt/index.php b/packages/block-library/src/post-excerpt/index.php index f35419eb9b2efc..a5bb80ce3b1b07 100644 --- a/packages/block-library/src/post-excerpt/index.php +++ b/packages/block-library/src/post-excerpt/index.php @@ -28,9 +28,9 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) { $filter_excerpt_length ); - $classes = 'wp-block-post-excerpt'; + $classes = ''; if ( isset( $attributes['textAlign'] ) ) { - $classes .= ' has-text-align-' . $attributes['textAlign']; + $classes .= 'has-text-align-' . $attributes['textAlign']; } $output = sprintf( '
', esc_attr( $classes ) ) . '

' . get_the_excerpt( $block->context['postId'] ); diff --git a/packages/block-library/src/post-tags/index.php b/packages/block-library/src/post-tags/index.php index f6ff4b075ae21c..6558eded3dad0d 100644 --- a/packages/block-library/src/post-tags/index.php +++ b/packages/block-library/src/post-tags/index.php @@ -20,9 +20,9 @@ function render_block_core_post_tags( $attributes, $content, $block ) { $post_tags = get_the_tags( $block->context['postId'] ); if ( ! empty( $post_tags ) ) { - $classes = 'wp-block-post-tags'; + $classes = ''; if ( isset( $attributes['textAlign'] ) ) { - $classes .= ' has-text-align-' . $attributes['textAlign']; + $classes .= 'has-text-align-' . $attributes['textAlign']; } $output = sprintf( '

', esc_attr( $classes ) ); diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php index 2f5b7535c91c6e..66f8161e24c3fa 100644 --- a/packages/block-library/src/post-title/index.php +++ b/packages/block-library/src/post-title/index.php @@ -20,7 +20,7 @@ function render_block_core_post_title( $attributes, $content, $block ) { } $tag_name = 'h2'; - $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}"; + $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; if ( isset( $attributes['level'] ) ) { $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level']; @@ -29,7 +29,7 @@ function render_block_core_post_title( $attributes, $content, $block ) { return sprintf( '<%1$s class="%2$s">%3$s', $tag_name, - 'wp-block-post-title' . esc_attr( $align_class_name ), + esc_attr( $align_class_name ), get_the_title( $block->context['postId'] ) ); } diff --git a/packages/block-library/src/rss/index.php b/packages/block-library/src/rss/index.php index 6c8792aa448d66..a3dbd0d431d02f 100644 --- a/packages/block-library/src/rss/index.php +++ b/packages/block-library/src/rss/index.php @@ -79,16 +79,16 @@ function render_block_core_rss( $attributes ) { $list_items .= "
  • {$title}{$date}{$author}{$excerpt}
  • "; } - $class = 'wp-block-rss'; + $classnames = array(); if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) { - $class .= ' is-grid'; + $classnames[] = 'is-grid'; } if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) { - $class .= ' columns-' . $attributes['columns']; + $classnames[] = 'columns-' . $attributes['columns']; } - return sprintf( '
      %s
    ', esc_attr( $class ), $list_items ); + return sprintf( '
      %s
    ', esc_attr( implode( ' ', $classnames ) ), $list_items ); } /** diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 7a224fa2eed3da..d1f7e84d2d915d 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -59,11 +59,8 @@ function render_block_core_search( $attributes ) { ); } - $class = 'wp-block-search'; - return sprintf( - '', - esc_attr( $class ), + '
    %s
    ', esc_url( home_url( '/' ) ), $label_markup . $input_markup . $button_markup ); diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index 66b3a84023af20..d0d8e7b4be2c31 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -23,16 +23,17 @@ function render_block_core_site_logo( $attributes ) { add_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter ); $custom_logo = get_custom_logo(); - $class_name = 'wp-block-site-logo'; + $classnames = array(); if ( ! empty( $attributes['className'] ) ) { - $class_name .= " {$attributes['className']}"; + $classnames[] = $attributes['className']; } if ( ! empty( $attributes['align'] ) && in_array( $attributes['align'], array( 'center', 'left', 'right' ), true ) ) { - $class_name .= " align{$attributes['align']}"; + $classnames[] = "align{$attributes['align']}"; } - $html = sprintf( '', $class_name, $custom_logo ); + $class_name = implode( ' ', $classnames ); + $html = sprintf( '', $class_name, $custom_logo ); remove_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter ); return $html; } diff --git a/packages/block-library/src/site-tagline/index.php b/packages/block-library/src/site-tagline/index.php index b450c1626adde8..39df38bec38501 100644 --- a/packages/block-library/src/site-tagline/index.php +++ b/packages/block-library/src/site-tagline/index.php @@ -13,11 +13,11 @@ * @return string The render. */ function render_block_core_site_tagline( $attributes ) { - $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}"; + $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; return sprintf( '

    %2$s

    ', - 'wp-block-site-tagline' . esc_attr( $align_class_name ), + esc_attr( $align_class_name ), get_bloginfo( 'description' ) ); } diff --git a/packages/block-library/src/site-title/index.php b/packages/block-library/src/site-title/index.php index 67baf2bc64dfd6..6f0ef7cd3d57f2 100644 --- a/packages/block-library/src/site-title/index.php +++ b/packages/block-library/src/site-title/index.php @@ -14,7 +14,7 @@ */ function render_block_core_site_title( $attributes ) { $tag_name = 'h1'; - $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}"; + $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; if ( isset( $attributes['level'] ) ) { $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level']; @@ -23,7 +23,7 @@ function render_block_core_site_title( $attributes ) { return sprintf( '<%1$s class="%2$s">%3$s', $tag_name, - 'wp-block-site-title' . esc_attr( $align_class_name ), + esc_attr( $align_class_name ), get_bloginfo( 'name' ) ); } diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php index 667c09a325651f..f417b786c45941 100644 --- a/packages/block-library/src/tag-cloud/index.php +++ b/packages/block-library/src/tag-cloud/index.php @@ -13,13 +13,11 @@ * @return string Returns the tag cloud for selected taxonomy. */ function render_block_core_tag_cloud( $attributes ) { - $class = 'wp-block-tag-cloud'; - $args = array( + $args = array( 'echo' => false, 'taxonomy' => $attributes['taxonomy'], 'show_count' => $attributes['showTagCounts'], ); - $tag_cloud = wp_tag_cloud( $args ); if ( ! $tag_cloud ) { @@ -34,8 +32,7 @@ function render_block_core_tag_cloud( $attributes ) { } return sprintf( - '

    %2$s

    ', - esc_attr( $class ), + '

    %1$s

    ', $tag_cloud ); } diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 82ba837fc4594e..27a08594eaca41 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -63,7 +63,7 @@ function render_block_core_template_part( $attributes ) { } $content = do_shortcode( $content ); - return '
    ' . str_replace( ']]>', ']]>', $content ) . '
    '; + return '
    ' . str_replace( ']]>', ']]>', $content ) . '
    '; } /** diff --git a/phpunit/class-block-supported-styles-test.php b/phpunit/class-block-supported-styles-test.php index 80dfd61b0c93db..77c1225074c37f 100644 --- a/phpunit/class-block-supported-styles-test.php +++ b/phpunit/class-block-supported-styles-test.php @@ -124,7 +124,7 @@ private function assert_content_and_styles_and_classes_match( $block, $expected_ * * @var string */ - const BLOCK_MARKUP = '
    ' . self::BLOCK_CONTENT . '
    '; + const BLOCK_MARKUP = '
    ' . self::BLOCK_CONTENT . '
    '; /** * Tests color support for named color support for named colors. @@ -152,7 +152,7 @@ function test_named_color_support() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-text-color has-red-color has-background has-black-background-color'; + $expected_classes = 'foo-bar-class wp-block-example has-text-color has-red-color has-background has-black-background-color'; $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -190,7 +190,7 @@ function test_custom_color_support() { ); $expected_styles = 'test: style; color: #000; background-color: #fff;'; - $expected_classes = 'wp-block-example foo-bar-class has-text-color has-background'; + $expected_classes = 'foo-bar-class wp-block-example has-text-color has-background'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -220,7 +220,7 @@ function test_named_link_color_support() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-link-color'; + $expected_classes = 'foo-bar-class wp-block-example has-link-color'; $expected_styles = 'test: style; --wp--style--color--link: var(--wp--preset--color--red);'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -251,7 +251,7 @@ function test_custom_link_color_support() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-link-color'; + $expected_classes = 'foo-bar-class wp-block-example has-link-color'; $expected_styles = 'test: style; --wp--style--color--link: #fff;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -282,7 +282,7 @@ function test_named_gradient_support() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-background has-red-gradient-background'; + $expected_classes = 'foo-bar-class wp-block-example has-background has-red-gradient-background'; $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -313,7 +313,7 @@ function test_custom_gradient_support() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-background'; + $expected_classes = 'foo-bar-class wp-block-example has-background'; $expected_styles = 'test: style; background: some-gradient-style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -349,8 +349,8 @@ function test_color_unsupported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; - $expected_styles = 'test:style;'; + $expected_classes = 'foo-bar-class wp-block-example'; + $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -378,7 +378,7 @@ function test_named_font_size() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-large-font-size'; + $expected_classes = 'foo-bar-class wp-block-example has-large-font-size'; $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -407,7 +407,7 @@ function test_custom_font_size() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; + $expected_classes = 'foo-bar-class wp-block-example'; $expected_styles = 'test: style; font-size: 10px;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -435,8 +435,8 @@ function test_font_size_unsupported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; - $expected_styles = 'test:style;'; + $expected_classes = 'foo-bar-class wp-block-example'; + $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -464,7 +464,7 @@ function test_line_height() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; + $expected_classes = 'foo-bar-class wp-block-example'; $expected_styles = 'test: style; line-height: 10;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -491,8 +491,8 @@ function test_line_height_unsupported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; - $expected_styles = 'test:style;'; + $expected_classes = 'foo-bar-class wp-block-example'; + $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -520,7 +520,7 @@ function test_block_alignment() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class alignwide'; + $expected_classes = 'foo-bar-class wp-block-example alignwide'; $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -547,8 +547,8 @@ function test_block_alignment_unsupported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; - $expected_styles = 'test:style;'; + $expected_classes = 'foo-bar-class wp-block-example'; + $expected_styles = 'test: style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -594,7 +594,7 @@ function test_all_supported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class has-text-color has-background alignwide'; + $expected_classes = 'foo-bar-class wp-block-example has-text-color has-background alignwide'; $expected_styles = 'test: style; color: #000; background-color: #fff; background: some-gradient; font-size: 10px; line-height: 20;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -636,7 +636,7 @@ function test_one_supported() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; + $expected_classes = 'foo-bar-class wp-block-example'; $expected_styles = 'test: style; font-size: 10px;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -682,7 +682,7 @@ function test_render_callback_required() { 'innerHTML' => array(), ); - $expected_classes = 'wp-block-example foo-bar-class'; + $expected_classes = 'foo-bar-class'; $expected_styles = 'test:style;'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); @@ -709,8 +709,8 @@ function test_custom_classnames_support() { 'innerHTML' => array(), ); - $expected_styles = 'test:style; '; - $expected_classes = 'wp-block-example foo-bar-class my-custom-classname'; + $expected_styles = 'test: style;'; + $expected_classes = 'foo-bar-class wp-block-example my-custom-classname'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); } @@ -738,8 +738,35 @@ function test_custom_classnames_support_opt_out() { 'innerHTML' => array(), ); + $expected_styles = 'test: style;'; + $expected_classes = 'foo-bar-class wp-block-example'; + + $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); + } + + /** + * Tests generated classname server-side block support opt-out. + */ + function test_generatted_classnames_support_opt_out() { + $block_type_settings = array( + 'attributes' => array(), + 'supports' => array( + 'className' => false, + ), + 'render_callback' => true, + ); + $this->register_block_type( 'core/example', $block_type_settings ); + + $block = array( + 'blockName' => 'core/example', + 'attrs' => array(), + 'innerBlock' => array(), + 'innerContent' => array(), + 'innerHTML' => array(), + ); + $expected_styles = 'test:style;'; - $expected_classes = 'wp-block-example foo-bar-class'; + $expected_classes = 'foo-bar-class'; $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); }