Make WordPress Core


Ignore:
Timestamp:
02/08/2024 08:16:59 AM (3 years ago)
Author:
gziolo
Message:

Editor: Make asset file optional for block scripts

It is no longer a hard requirement that a *.asset.php file is present to register a script for block.

Fixes #57234.
Props joefusco, gziolo, spacedmonkey, colorful-tones.

File:
1 edited

Legend:

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

    r57493 r57559  
    6161                }
    6262
     63                foreach ( wp_scripts()->registered as $script_handle => $script ) {
     64                        if ( str_starts_with( $script_handle, 'unit-tests-' ) ) {
     65                                wp_deregister_script( $script_handle );
     66                        }
     67                }
     68
    6369                parent::tear_down();
    6470        }
     
    227233
    228234        /**
    229          * @expectedIncorrectUsage register_block_script_handle
    230          * @ticket 50263
    231          */
    232         public function test_missing_asset_file_register_block_script_handle() {
     235         * @ticket 50263
     236         */
     237        public function test_handle_passed_register_block_script_handle() {
     238                $metadata = array(
     239                        'script' => 'test-script-handle',
     240                );
     241                $result   = register_block_script_handle( $metadata, 'script' );
     242
     243                $this->assertSame( 'test-script-handle', $result );
     244        }
     245
     246        public function test_handles_passed_register_block_script_handles() {
     247                $metadata = array(
     248                        'script' => array( 'test-script-handle', 'test-script-handle-2' ),
     249                );
     250
     251                $result = register_block_script_handle( $metadata, 'script' );
     252                $this->assertSame( 'test-script-handle', $result );
     253
     254                $result = register_block_script_handle( $metadata, 'script', 1 );
     255                $this->assertSame( 'test-script-handle-2', $result, 1 );
     256        }
     257
     258        /**
     259         * @ticket 50263
     260         * @ticket 60460
     261         */
     262        public function test_missing_asset_file_register_block_script_handle_with_default_settings() {
    233263                $metadata = array(
    234264                        'file'   => __FILE__,
     
    238268                $result   = register_block_script_handle( $metadata, 'script' );
    239269
    240                 $this->assertFalse( $result );
    241         }
    242 
    243         /**
    244          * @ticket 50263
    245          */
    246         public function test_handle_passed_register_block_script_handle() {
    247                 $metadata = array(
    248                         'script' => 'test-script-handle',
    249                 );
    250                 $result   = register_block_script_handle( $metadata, 'script' );
    251 
    252                 $this->assertSame( 'test-script-handle', $result );
    253         }
    254 
    255         public function test_handles_passed_register_block_script_handles() {
    256                 $metadata = array(
    257                         'script' => array( 'test-script-handle', 'test-script-handle-2' ),
    258                 );
    259 
    260                 $result = register_block_script_handle( $metadata, 'script' );
    261                 $this->assertSame( 'test-script-handle', $result );
    262 
    263                 $result = register_block_script_handle( $metadata, 'script', 1 );
    264                 $this->assertSame( 'test-script-handle-2', $result, 1 );
     270                $this->assertSame( 'unit-tests-test-block-script', $result );
    265271        }
    266272
Note: See TracChangeset for help on using the changeset viewer.