diff --git a/tests/phpunit/tests/block-supports/layout.php b/tests/phpunit/tests/block-supports/layout.php index 929823d147bfa..3b71b2c4b7482 100644 --- a/tests/phpunit/tests/block-supports/layout.php +++ b/tests/phpunit/tests/block-supports/layout.php @@ -637,4 +637,84 @@ 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', + ), + ); + } }