Make WordPress Core

Ticket #52592: 52592-tests.diff

File 52592-tests.diff, 3.7 KB (added by Rahmohn, 17 months ago)

Refactoring and adding tests

  • tests/phpunit/tests/blocks/wpBlockStylesRegistry.php

    diff --git a/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php b/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php
    index f73ba67ba1..33cb3d0e8c 100644
    a b class Tests_Blocks_wpBlockStylesRegistry extends WP_UnitTestCase { 
    4747         */
    4848        public function test_register_block_style_with_string_block_name() {
    4949                $name             = 'core/paragraph';
    50                 $style_properties = array( 'name' => 'fancy' );
     50                $style_properties = array(
     51                        'name'  => 'fancy',
     52                        'label' => 'Fancy',
     53                );
    5154                $result           = $this->registry->register( $name, $style_properties );
    5255                $this->assertTrue( $result );
    5356                $this->assertTrue( $this->registry->is_registered( 'core/paragraph', 'fancy' ) );
    class Tests_Blocks_wpBlockStylesRegistry extends WP_UnitTestCase { 
    6063         */
    6164        public function test_register_block_style_with_array_of_block_names() {
    6265                $names            = array( 'core/paragraph', 'core/group' );
    63                 $style_properties = array( 'name' => 'plain' );
     66                $style_properties = array(
     67                        'name'  => 'plain',
     68                        'label' => 'Plain',
     69                );
    6470                $result           = $this->registry->register( $names, $style_properties );
    6571                $this->assertTrue( $result );
    6672                $this->assertTrue( $this->registry->is_registered( 'core/paragraph', 'plain' ) );
    6773                $this->assertTrue( $this->registry->is_registered( 'core/group', 'plain' ) );
    6874        }
     75
     76        /**
     77         * Should accept valid string style label.
     78         * The registered style should have the same label.
     79         *
     80         * @ticket 52592
     81         *
     82         * @covers WP_Block_Styles_Registry::register
     83         * @covers WP_Block_Styles_Registry::is_registered
     84         * @covers WP_Block_Styles_Registry::get_registered_styles_for_block
     85         */
     86        public function test_register_block_style_with_string_style_label() {
     87                $name             = 'core/paragraph';
     88                $style_properties = array(
     89                        'name'  => 'fancy',
     90                        'label' => 'Fancy',
     91                );
     92                $result           = $this->registry->register( $name, $style_properties );
     93
     94                $this->assertTrue( $result, 'The block style should be registered when the label is a valid string.' );
     95                $this->assertTrue(
     96                        $this->registry->is_registered( $name, 'fancy' ),
     97                        'The block type should have the block style registered when the label is valid.'
     98                );
     99                $this->assertEquals(
     100                        $style_properties['label'],
     101                        $this->registry->get_registered_styles_for_block( $name )['fancy']['label'],
     102                        'The registered block style should have the same label.'
     103                );
     104        }
     105
     106        /**
     107         * Should not accept invalid style label.
     108         *
     109         * @ticket 52592
     110         *
     111         * @covers WP_Block_Styles_Registry::register
     112         * @covers WP_Block_Styles_Registry::is_registered
     113         */
     114        public function test_register_block_style_with_invalid_style_label() {
     115                $name             = 'core/paragraph';
     116                $style_properties = array(
     117                        'name' => 'fancy',
     118                );
     119
     120                $this->setExpectedIncorrectUsage( 'WP_Block_Styles_Registry::register' );
     121
     122                $result           = $this->registry->register( $name, $style_properties );
     123                $this->assertFalse( $result, 'The block style should not be registered when the label property is missing.' );
     124                $this->assertFalse(
     125                        $this->registry->is_registered( $name, 'fancy' ),
     126                        'The block type should not have the block style registered when the label property is missing.'
     127                );
     128
     129                $style_properties['label'] = ['Fancy'];
     130
     131                $result           = $this->registry->register( $name, $style_properties );
     132                $this->assertFalse( $result, 'The block style should not be registered when the label property is not a string.' );
     133                $this->assertFalse(
     134                        $this->registry->is_registered( $name, 'fancy' ),
     135                        'The block type should not have the block style registered when the label property is not a string.'
     136                );
     137        }
    69138}