From 52450e274984e499fb1f43b46d32f51cd1462da3 Mon Sep 17 00:00:00 2001 From: Rishabh Gupta Date: Wed, 20 Aug 2025 12:54:56 +0530 Subject: [PATCH 1/2] tests: add tests for block layout classname generation --- tests/phpunit/tests/block-supports/layout.php | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/tests/phpunit/tests/block-supports/layout.php b/tests/phpunit/tests/block-supports/layout.php index 38c9cce4afaca..782771e0aef3d 100644 --- a/tests/phpunit/tests/block-supports/layout.php +++ b/tests/phpunit/tests/block-supports/layout.php @@ -637,4 +637,151 @@ public function data_layout_support_flag_renders_consistent_container_hash() { ), ); } + + /** + * Tests that custom blocks include namespace in layout classnames. + * + * When layout support is enabled for custom blocks, the generated + * layout classname should include the full block namespace to ensure + * that CSS selectors match correctly. + * + * @ticket 63839 + * @covers ::wp_render_layout_support_flag + * + * @dataProvider data_layout_classname_with_custom_blocks + */ + public function test_layout_classname_includes_namespace_for_custom_blocks( $block_name, $layout_type, $expected_class, $should_not_contain ) { + switch_theme( 'default' ); + + register_block_type( + $block_name, + array( + 'supports' => array( + 'layout' => true, + ), + ) + ); + + $block_content = '

Content

'; + $block = array( + 'blockName' => $block_name, + 'attrs' => array( + 'layout' => array( + 'type' => $layout_type, + ), + ), + ); + + $output = wp_render_layout_support_flag( $block_content, $block ); + + // Assert that the expected class is present. + $this->assertStringContainsString( $expected_class, $output ); + + // Assert that the old buggy class is not present. + $this->assertStringNotContainsString( $should_not_contain, $output ); + + // Clean up the registered block type. + unregister_block_type( $block_name ); + } + + /** + * Data provider for test_layout_classname_includes_namespace_for_custom_blocks. + * + * @return array + */ + public function data_layout_classname_with_custom_blocks() { + return array( + 'custom block with constrained layout' => array( + 'block_name' => 'foo/bar', + 'layout_type' => 'constrained', + 'expected_class' => 'wp-block-foo-bar-is-layout-constrained', + 'should_not_contain' => 'wp-block-bar-is-layout-constrained', + ), + 'custom block with default layout' => array( + 'block_name' => 'foo/bar', + 'layout_type' => 'default', + 'expected_class' => 'wp-block-foo-bar-is-layout-flow', + 'should_not_contain' => 'wp-block-bar-is-layout-flow', + ), + 'custom block with flex layout' => array( + 'block_name' => 'foo/bar', + 'layout_type' => 'flex', + 'expected_class' => 'wp-block-foo-bar-is-layout-flex', + 'should_not_contain' => 'wp-block-bar-is-layout-flex', + ), + 'custom block with grid layout' => array( + 'block_name' => 'foo/bar', + 'layout_type' => 'grid', + 'expected_class' => 'wp-block-foo-bar-is-layout-grid', + 'should_not_contain' => 'wp-block-bar-is-layout-grid', + ), + ); + } + + /** + * Tests that core blocks maintain correct layout classnames (regression test). + * + * This test ensures that the fix for custom block layout classnames + * doesn't break the existing behavior for core blocks. + * + * @ticket 63839 + * @covers ::wp_render_layout_support_flag + * + * @dataProvider data_layout_classname_with_core_blocks + */ + public function test_layout_classname_works_for_core_blocks( $block_name, $layout_type, $expected_class, $should_not_contain ) { + switch_theme( 'default' ); + + $block_content = '

Content

'; + $block = array( + 'blockName' => $block_name, + 'attrs' => array( + 'layout' => array( + 'type' => $layout_type, + ), + ), + ); + + $output = wp_render_layout_support_flag( $block_content, $block ); + + // Assert that core blocks use only the block name without namespace. + $this->assertStringContainsString( $expected_class, $output ); + + // Assert that core blocks don't include the 'core' namespace prefix. + $this->assertStringNotContainsString( $should_not_contain, $output ); + } + + /** + * Data provider for test_layout_classname_works_for_core_blocks. + * + * @return array + */ + public function data_layout_classname_with_core_blocks() { + return array( + 'core group block with constrained layout' => array( + 'block_name' => 'core/group', + 'layout_type' => 'constrained', + 'expected_class' => 'wp-block-group-is-layout-constrained', + 'should_not_contain' => 'wp-block-core-group-is-layout-constrained', + ), + 'core cover block with default layout' => array( + 'block_name' => 'core/cover', + 'layout_type' => 'default', + 'expected_class' => 'wp-block-cover-is-layout-flow', + 'should_not_contain' => 'wp-block-core-cover-is-layout-flow', + ), + 'core columns block with flex layout' => array( + 'block_name' => 'core/columns', + 'layout_type' => 'flex', + 'expected_class' => 'wp-block-columns-is-layout-flex', + 'should_not_contain' => 'wp-block-core-columns-is-layout-flex', + ), + 'core group block with grid layout' => array( + 'block_name' => 'core/group', + 'layout_type' => 'grid', + 'expected_class' => 'wp-block-group-is-layout-grid', + 'should_not_contain' => 'wp-block-core-group-is-layout-grid', + ), + ); + } } From 7e234f0160e951b70e4c66574be978da084a34ca Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Fri, 7 Nov 2025 09:48:17 +0900 Subject: [PATCH 2/2] Remove unnecessary unit test --- tests/phpunit/tests/block-supports/layout.php | 67 ------------------- 1 file changed, 67 deletions(-) diff --git a/tests/phpunit/tests/block-supports/layout.php b/tests/phpunit/tests/block-supports/layout.php index e681ffe3b2209..3b71b2c4b7482 100644 --- a/tests/phpunit/tests/block-supports/layout.php +++ b/tests/phpunit/tests/block-supports/layout.php @@ -717,71 +717,4 @@ public function data_layout_classname_with_custom_blocks() { ), ); } - - /** - * Tests that core blocks maintain correct layout classnames (regression test). - * - * This test ensures that the fix for custom block layout classnames - * doesn't break the existing behavior for core blocks. - * - * @ticket 63839 - * @covers ::wp_render_layout_support_flag - * - * @dataProvider data_layout_classname_with_core_blocks - */ - public function test_layout_classname_works_for_core_blocks( $block_name, $layout_type, $expected_class, $should_not_contain ) { - switch_theme( 'default' ); - - $block_content = '

Content

'; - $block = array( - 'blockName' => $block_name, - 'attrs' => array( - 'layout' => array( - 'type' => $layout_type, - ), - ), - ); - - $output = wp_render_layout_support_flag( $block_content, $block ); - - // Assert that core blocks use only the block name without namespace. - $this->assertStringContainsString( $expected_class, $output ); - - // Assert that core blocks don't include the 'core' namespace prefix. - $this->assertStringNotContainsString( $should_not_contain, $output ); - } - - /** - * Data provider for test_layout_classname_works_for_core_blocks. - * - * @return array - */ - public function data_layout_classname_with_core_blocks() { - return array( - 'core group block with constrained layout' => array( - 'block_name' => 'core/group', - 'layout_type' => 'constrained', - 'expected_class' => 'wp-block-group-is-layout-constrained', - 'should_not_contain' => 'wp-block-core-group-is-layout-constrained', - ), - 'core cover block with default layout' => array( - 'block_name' => 'core/cover', - 'layout_type' => 'default', - 'expected_class' => 'wp-block-cover-is-layout-flow', - 'should_not_contain' => 'wp-block-core-cover-is-layout-flow', - ), - 'core columns block with flex layout' => array( - 'block_name' => 'core/columns', - 'layout_type' => 'flex', - 'expected_class' => 'wp-block-columns-is-layout-flex', - 'should_not_contain' => 'wp-block-core-columns-is-layout-flex', - ), - 'core group block with grid layout' => array( - 'block_name' => 'core/group', - 'layout_type' => 'grid', - 'expected_class' => 'wp-block-group-is-layout-grid', - 'should_not_contain' => 'wp-block-core-group-is-layout-grid', - ), - ); - } }