@@ -7829,6 +7829,193 @@ public function test_opt_in_to_block_style_variations() {
78297829 $ this ->assertSame ( $ expected , $ button_variations );
78307830 }
78317831
7832+ /**
7833+ * Tests that a block style variation declaring `spacing.blockGap` emits a layout
7834+ * gap rule scoped to the variation.
7835+ *
7836+ * The variation node carries the variation slug in its `name`, which
7837+ * `get_layout_styles()` reads as a block name. The metadata passed to that
7838+ * method therefore has to name the block the variation belongs to.
7839+ *
7840+ * @ticket 66044
7841+ *
7842+ * @covers WP_Theme_JSON::get_styles_for_block
7843+ */
7844+ public function test_block_style_variation_with_block_gap_emits_layout_styles () {
7845+ $ registry = WP_Block_Styles_Registry::get_instance ();
7846+ $ registry ->register ( 'core/group ' , array ( 'name ' => 'custom-group ' ) );
7847+
7848+ $ theme_json = new WP_Theme_JSON (
7849+ array (
7850+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
7851+ 'settings ' => array (
7852+ 'spacing ' => array (
7853+ 'blockGap ' => true ,
7854+ ),
7855+ ),
7856+ 'styles ' => array (
7857+ 'blocks ' => array (
7858+ 'core/group ' => array (
7859+ 'variations ' => array (
7860+ 'custom-group ' => array (
7861+ 'spacing ' => array (
7862+ 'blockGap ' => '3em ' ,
7863+ ),
7864+ ),
7865+ ),
7866+ ),
7867+ ),
7868+ ),
7869+ ),
7870+ 'blocks '
7871+ );
7872+
7873+ $ stylesheet = $ theme_json ->get_stylesheet (
7874+ array ( 'styles ' ),
7875+ array ( 'custom ' ),
7876+ array (
7877+ 'include_block_style_variations ' => true ,
7878+ 'skip_root_layout_styles ' => true ,
7879+ )
7880+ );
7881+
7882+ $ registry ->unregister ( 'core/group ' , 'custom-group ' );
7883+
7884+ $ this ->assertStringContainsString (
7885+ ':root :where(.wp-block-group.is-style-custom-group.wp-block-group-is-layout-flex){gap: 3em;} ' ,
7886+ $ stylesheet ,
7887+ 'The variation should emit a gap rule scoped to itself. '
7888+ );
7889+ }
7890+
7891+ /**
7892+ * Tests that a block style variation declaring `spacing.blockGap` inside a
7893+ * viewport breakpoint emits a layout gap rule within the media query.
7894+ *
7895+ * The responsive branch takes its own copy of the variation metadata, so it
7896+ * needs the owning block name for the same reason the base branch does.
7897+ *
7898+ * @ticket 66044
7899+ *
7900+ * @covers WP_Theme_JSON::get_styles_for_block
7901+ */
7902+ public function test_block_style_variation_with_responsive_block_gap_emits_layout_styles () {
7903+ $ registry = WP_Block_Styles_Registry::get_instance ();
7904+ $ registry ->register ( 'core/group ' , array ( 'name ' => 'custom-group ' ) );
7905+
7906+ $ theme_json = new WP_Theme_JSON (
7907+ array (
7908+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
7909+ 'settings ' => array (
7910+ 'spacing ' => array (
7911+ 'blockGap ' => true ,
7912+ ),
7913+ 'viewport ' => array (
7914+ 'mobile ' => '599px ' ,
7915+ ),
7916+ ),
7917+ 'styles ' => array (
7918+ 'blocks ' => array (
7919+ 'core/group ' => array (
7920+ 'variations ' => array (
7921+ 'custom-group ' => array (
7922+ 'spacing ' => array (
7923+ 'blockGap ' => '3em ' ,
7924+ ),
7925+ '@mobile ' => array (
7926+ 'spacing ' => array (
7927+ 'blockGap ' => '1em ' ,
7928+ ),
7929+ ),
7930+ ),
7931+ ),
7932+ ),
7933+ ),
7934+ ),
7935+ ),
7936+ 'blocks '
7937+ );
7938+
7939+ $ stylesheet = $ theme_json ->get_stylesheet (
7940+ array ( 'styles ' ),
7941+ array ( 'custom ' ),
7942+ array (
7943+ 'include_block_style_variations ' => true ,
7944+ 'skip_root_layout_styles ' => true ,
7945+ )
7946+ );
7947+
7948+ $ registry ->unregister ( 'core/group ' , 'custom-group ' );
7949+
7950+ $ this ->assertStringContainsString (
7951+ '@media (width <= 599px) ' ,
7952+ $ stylesheet ,
7953+ 'The breakpoint media query should be emitted. '
7954+ );
7955+ $ this ->assertStringContainsString (
7956+ ':root :where(.wp-block-group.is-style-custom-group.wp-block-group-is-layout-flex){gap: 1em;} ' ,
7957+ $ stylesheet ,
7958+ 'The variation should emit a gap rule inside the breakpoint. '
7959+ );
7960+ }
7961+
7962+ /**
7963+ * Tests that the layout support check still applies to a variation's blockGap.
7964+ *
7965+ * The variation metadata carries the block it belongs to, so a block without
7966+ * layout support emits no gap rule -- the check is answered, not skipped.
7967+ *
7968+ * @ticket 66044
7969+ *
7970+ * @covers WP_Theme_JSON::get_styles_for_block
7971+ */
7972+ public function test_block_style_variation_block_gap_respects_layout_support () {
7973+ $ registry = WP_Block_Styles_Registry::get_instance ();
7974+ $ registry ->register ( 'core/paragraph ' , array ( 'name ' => 'custom-paragraph ' ) );
7975+
7976+ $ theme_json = new WP_Theme_JSON (
7977+ array (
7978+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
7979+ 'settings ' => array (
7980+ 'spacing ' => array (
7981+ 'blockGap ' => true ,
7982+ ),
7983+ ),
7984+ 'styles ' => array (
7985+ 'blocks ' => array (
7986+ 'core/paragraph ' => array (
7987+ 'variations ' => array (
7988+ 'custom-paragraph ' => array (
7989+ 'spacing ' => array (
7990+ 'blockGap ' => '3em ' ,
7991+ ),
7992+ ),
7993+ ),
7994+ ),
7995+ ),
7996+ ),
7997+ ),
7998+ 'blocks '
7999+ );
8000+
8001+ $ stylesheet = $ theme_json ->get_stylesheet (
8002+ array ( 'styles ' ),
8003+ array ( 'custom ' ),
8004+ array (
8005+ 'include_block_style_variations ' => true ,
8006+ 'skip_root_layout_styles ' => true ,
8007+ )
8008+ );
8009+
8010+ $ registry ->unregister ( 'core/paragraph ' , 'custom-paragraph ' );
8011+
8012+ $ this ->assertStringNotContainsString (
8013+ 'is-style-custom-paragraph ' ,
8014+ $ stylesheet ,
8015+ 'core/paragraph has no layout support, so its variation should emit no gap rule. '
8016+ );
8017+ }
8018+
78328019 /**
78338020 * Tests that block-level settings inherit global default settings when not explicitly set.
78348021 *
0 commit comments