Make WordPress Core

Changeset 61186


Ignore:
Timestamp:
11/08/2025 01:46:21 PM (23 hours ago)
Author:
SergeyBiryukov
Message:

Tests: Add unit tests for a label fallback in WP_Block_Styles_Registry::register().

Follow-up to [59760].

Props Rahmohn, mukesh27, SergeyBiryukov.
See #63167.

File:
1 edited

Legend:

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

    r60904 r61186  
    88 *
    99 * @group blocks
     10 * @coversDefaultClass WP_Block_Styles_Registry
    1011 */
    1112class Tests_Blocks_wpBlockStylesRegistry extends WP_UnitTestCase {
     
    6970
    7071    /**
     72     * Should accept valid string style label. The registered style should have the same label.
     73     *
     74     * @ticket 52592
     75     *
     76     * @covers ::register
     77     * @covers ::is_registered
     78     * @covers ::get_registered_styles_for_block
     79     */
     80    public function test_register_block_style_with_label() {
     81        $name             = 'core/paragraph';
     82        $style_properties = array(
     83            'name'  => 'fancy',
     84            'label' => 'Fancy',
     85        );
     86        $result           = $this->registry->register( $name, $style_properties );
     87
     88        $this->assertTrue( $result, 'The block style should be registered when the label is a valid string.' );
     89        $this->assertTrue(
     90            $this->registry->is_registered( $name, 'fancy' ),
     91            'The block type should have the block style registered when the label is valid.'
     92        );
     93        $this->assertSame(
     94            $style_properties['label'],
     95            $this->registry->get_registered_styles_for_block( $name )['fancy']['label'],
     96            'The registered block style should have the same label.'
     97        );
     98    }
     99
     100    /**
     101     * Should register the block style when `label` is missing, using `name` as the label.
     102     *
     103     * @ticket 52592
     104     *
     105     * @covers ::register
     106     * @covers ::is_registered
     107     * @covers ::get_registered_styles_for_block
     108     */
     109    public function test_register_block_style_without_label() {
     110        $name             = 'core/paragraph';
     111        $style_properties = array(
     112            'name' => 'fancy',
     113        );
     114        $result           = $this->registry->register( $name, $style_properties );
     115
     116        $this->assertTrue( $result, 'The block style should be registered when the label is missing.' );
     117        $this->assertTrue(
     118            $this->registry->is_registered( $name, 'fancy' ),
     119            'The block type should have the block style registered when the label is missing.'
     120        );
     121        $this->assertSame(
     122            $style_properties['name'],
     123            $this->registry->get_registered_styles_for_block( $name )['fancy']['label'],
     124            'The registered block style label should be the same as the name.'
     125        );
     126    }
     127
     128    /**
    71129     * @ticket 63957
    72130     */
Note: See TracChangeset for help on using the changeset viewer.