From 9ec91036693d7baacf613fa925b792cd999f216d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 8 Mar 2023 15:00:12 +0000 Subject: [PATCH] Tests: Add a unit test for `register_block_style_handle()` with an RTL locale. The test ensures that the function loads RTL stylesheets when a locale with the right-to-left text direction is set. Follow-up to [54330]. Props costdev, thomasplevy, audrasjb, mukesh27. Fixes #56797. git-svn-id: https://develop.svn.wordpress.org/trunk@55486 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/blocks/register.php | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 17bc36f50d..e1cd22db45 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -368,6 +368,58 @@ class Tests_Blocks_Register extends WP_UnitTestCase { ); } + /** + * Tests that register_block_style_handle() loads RTL stylesheets when an RTL locale is set. + * + * @ticket 56325 + * @ticket 56797 + * + * @covers ::register_block_style_handle + */ + public function test_register_block_style_handle_should_load_rtl_stylesheets_for_rtl_text_direction() { + global $wp_locale; + + $metadata = array( + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', + 'name' => 'unit-tests/test-block-rtl', + 'style' => 'file:./block.css', + ); + + $orig_text_dir = $wp_locale->text_direction; + $wp_locale->text_direction = 'rtl'; + + $handle = register_block_style_handle( $metadata, 'style' ); + $extra_rtl = wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'rtl' ); + $extra_suffix = wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'suffix' ); + $extra_path = wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'path' ) ); + + $wp_locale->text_direction = $orig_text_dir; + + $this->assertSame( + 'unit-tests-test-block-rtl-style', + $handle, + 'The handle did not match the expected handle.' + ); + + $this->assertSame( + 'replace', + $extra_rtl, + 'The extra "rtl" data was not "replace".' + ); + + $this->assertSame( + '', + $extra_suffix, + 'The extra "suffix" data was not an empty string.' + ); + + $this->assertSame( + wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block-rtl.css' ) ), + $extra_path, + 'The "path" did not match the expected path.' + ); + } + /** * @ticket 56664 */