Make WordPress Core


Ignore:
Timestamp:
03/08/2023 03:00:12 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/register.php

    r55457 r55486  
    370370
    371371        /**
     372         * Tests that register_block_style_handle() loads RTL stylesheets when an RTL locale is set.
     373         *
     374         * @ticket 56325
     375         * @ticket 56797
     376         *
     377         * @covers ::register_block_style_handle
     378         */
     379        public function test_register_block_style_handle_should_load_rtl_stylesheets_for_rtl_text_direction() {
     380                global $wp_locale;
     381
     382                $metadata = array(
     383                        'file'  => DIR_TESTDATA . '/blocks/notice/block.json',
     384                        'name'  => 'unit-tests/test-block-rtl',
     385                        'style' => 'file:./block.css',
     386                );
     387
     388                $orig_text_dir             = $wp_locale->text_direction;
     389                $wp_locale->text_direction = 'rtl';
     390
     391                $handle       = register_block_style_handle( $metadata, 'style' );
     392                $extra_rtl    = wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'rtl' );
     393                $extra_suffix = wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'suffix' );
     394                $extra_path   = wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-rtl-style', 'path' ) );
     395
     396                $wp_locale->text_direction = $orig_text_dir;
     397
     398                $this->assertSame(
     399                        'unit-tests-test-block-rtl-style',
     400                        $handle,
     401                        'The handle did not match the expected handle.'
     402                );
     403
     404                $this->assertSame(
     405                        'replace',
     406                        $extra_rtl,
     407                        'The extra "rtl" data was not "replace".'
     408                );
     409
     410                $this->assertSame(
     411                        '',
     412                        $extra_suffix,
     413                        'The extra "suffix" data was not an empty string.'
     414                );
     415
     416                $this->assertSame(
     417                        wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block-rtl.css' ) ),
     418                        $extra_path,
     419                        'The "path" did not match the expected path.'
     420                );
     421        }
     422
     423        /**
    372424         * @ticket 56664
    373425         */
Note: See TracChangeset for help on using the changeset viewer.