From 3293802f2e9737d41e8e3766ca36a9d30bcdedf7 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 30 Oct 2023 11:26:35 +0530 Subject: [PATCH 1/2] Fix blocks RTL style loading issue --- src/wp-includes/blocks/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php index 6832759e77d98..40967727da574 100644 --- a/src/wp-includes/blocks/index.php +++ b/src/wp-includes/blocks/index.php @@ -106,11 +106,11 @@ static function ( $file ) use ( $normalized_blocks_path ) { $wp_styles->add( $style_handle, $blocks_url . $style_path ); $wp_styles->add_data( $style_handle, 'path', $path ); - $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ); + $rtl_file = "{$name}/{$filename}-rtl{$suffix}.css"; if ( is_rtl() && in_array( $rtl_file, $files, true ) ) { $wp_styles->add_data( $style_handle, 'rtl', 'replace' ); $wp_styles->add_data( $style_handle, 'suffix', $suffix ); - $wp_styles->add_data( $style_handle, 'path', $rtl_file ); + $wp_styles->add_data( $style_handle, 'path', str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ) ); } }; From 3f3ab83c58fe49886444ea63d2d26bc6fcb94e35 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 30 Oct 2023 16:47:34 +0530 Subject: [PATCH 2/2] Add unit test --- .../blocks/registerCoreBlockStyleHandles.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php b/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php index a4ed1dd418c72..92ce38738c4e2 100644 --- a/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php +++ b/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php @@ -132,6 +132,41 @@ public function test_wp_should_load_separate_core_block_assets_current_theme_sup } } + /** + * @ticket 59715 + * + * @dataProvider data_block_data + * + * @param string $name The block name. + */ + public function test_register_core_block_style_handles_should_load_rtl_stylesheets_for_rtl_text_direction( $name ) { + global $wp_locale; + + $orig_text_dir = $wp_locale->text_direction; + $wp_locale->text_direction = 'rtl'; + + add_filter( 'should_load_separate_core_block_assets', '__return_true' ); + add_theme_support( 'wp-block-styles' ); + register_core_block_style_handles(); + + $wp_styles = $GLOBALS['wp_styles']; + + $style_handle = "wp-block-{$name}-theme"; + + $wp_locale->text_direction = $orig_text_dir; + + $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); + if ( false === $wp_styles->registered[ $style_handle ]->src ) { + $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' ); + } else { + $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); + $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); + $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); + $this->assertArrayHasKey( 'rtl', $wp_styles->registered[ $style_handle ]->extra, 'The rtl key of the style should exist in extra array' ); + $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); + } + } + public function data_block_data() { $core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php';