Make WordPress Core


Ignore:
Timestamp:
04/18/2026 04:45:54 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use a data provider in a WP_Block_Type_Registry test for invalid block names.

Includes adding missing @covers tags.

Follow-up to [43742], [51491].

Props sagardeshmukh.
See #64225.

File:
1 edited

Legend:

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

    r55457 r62245  
    88 *
    99 * @group blocks
     10 *
     11 * @coversDefaultClass WP_Block_Type_Registry
    1012 */
    1113class Tests_Blocks_wpBlockTypeRegistry extends WP_UnitTestCase {
    … …  
    4244
    4345        /**
    44          * Should reject numbers
     46         * Should reject invalid block names.
    4547         *
    4648         * @ticket 45097
    4749         *
     50         * @covers ::register
     51         *
     52         * @dataProvider data_invalid_block_names
     53         *
    4854         * @expectedIncorrectUsage WP_Block_Type_Registry::register
    4955         */
    50         public function test_invalid_non_string_names() {
    51                 $result = $this->registry->register( 1, array() );
     56        public function test_invalid_block_names( $name ) {
     57                $result = $this->registry->register( $name, array() );
    5258                $this->assertFalse( $result );
    5359        }
    5460
    5561        /**
    56          * Should reject blocks without a namespace
     62         * Data provider for test_invalid_block_names().
     63         *
     64         * @return array<string, array{ 0: mixed }>
     65         */
     66        public function data_invalid_block_names(): array {
     67                return array(
     68                        'non-string name'      => array( 1 ),
     69                        'no namespace'         => array( 'paragraph' ),
     70                        'invalid characters'   => array( 'still/_doing_it_wrong' ),
     71                        'uppercase characters' => array( 'Core/Paragraph' ),
     72                );
     73        }
     74
     75        /**
     76         * Should accept valid block names.
    5777         *
    5878         * @ticket 45097
    5979         *
    60          * @expectedIncorrectUsage WP_Block_Type_Registry::register
    61          */
    62         public function test_invalid_names_without_namespace() {
    63                 $result = $this->registry->register( 'paragraph', array() );
    64                 $this->assertFalse( $result );
    65         }
    66 
    67         /**
    68          * Should reject blocks with invalid characters
    69          *
    70          * @ticket 45097
    71          *
    72          * @expectedIncorrectUsage WP_Block_Type_Registry::register
    73          */
    74         public function test_invalid_characters() {
    75                 $result = $this->registry->register( 'still/_doing_it_wrong', array() );
    76                 $this->assertFalse( $result );
    77         }
    78 
    79         /**
    80          * Should reject blocks with uppercase characters
    81          *
    82          * @ticket 45097
    83          *
    84          * @expectedIncorrectUsage WP_Block_Type_Registry::register
    85          */
    86         public function test_uppercase_characters() {
    87                 $result = $this->registry->register( 'Core/Paragraph', array() );
    88                 $this->assertFalse( $result );
    89         }
    90 
    91         /**
    92          * Should accept valid block names
    93          *
    94          * @ticket 45097
     80         * @covers ::register
     81         * @covers ::get_registered
    9582         */
    9683        public function test_register_block_type() {
    … …  
    10794
    10895        /**
    109          * Should fail to re-register the same block
     96         * Should fail to re-register the same block.
    11097         *
    11198         * @ticket 45097
     99         *
     100         * @covers ::register
    112101         *
    113102         * @expectedIncorrectUsage WP_Block_Type_Registry::register
    … …  
    126115
    127116        /**
    128          * Should accept a WP_Block_Type instance
     117         * Should accept a WP_Block_Type instance.
    129118         *
    130119         * @ticket 45097
     120         *
     121         * @covers ::register
    131122         */
    132123        public function test_register_block_type_instance() {
    … …  
    138129
    139130        /**
    140          * Unregistering should fail if a block is not registered
     131         * Unregistering should fail if a block is not registered.
    141132         *
    142133         * @ticket 45097
     134         *
     135         * @covers ::unregister
    143136         *
    144137         * @expectedIncorrectUsage WP_Block_Type_Registry::unregister
    … …  
    150143
    151144        /**
    152          * Should unregister existing blocks
     145         * Should unregister existing blocks.
    153146         *
    154147         * @ticket 45097
     148         *
     149         * @covers ::unregister
     150         * @covers ::is_registered
    155151         */
    156152        public function test_unregister_block_type() {
    … …  
    169165        /**
    170166         * @ticket 45097
     167         *
     168         * @covers ::get_all_registered
    171169         */
    172170        public function test_get_all_registered() {
Note: See TracChangeset for help on using the changeset viewer.