Make WordPress Core


Ignore:
Timestamp:
04/07/2022 11:57:16 AM (3 years ago)
Author:
gziolo
Message:

Editor: Allow registration of blocks that include assets from within a theme

Fixes the issue when you register blocks with block.json in your theme. There is no longer an assets's URL error because it resolves correctly in relation to the theme where it is located.

Props fabiankaegy, ocean90, whoisnegrello, audrasjb, peterwilsoncc,
Fixes #54647, #55513.

File:
1 edited

Legend:

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

    r52699 r53091  
    254254
    255255    /**
     256     * @ticket 55513
     257     */
     258    public function test_success_register_block_script_handle_in_theme() {
     259        switch_theme( 'block-theme' );
     260
     261        $metadata = array(
     262            'file'       => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ),
     263            'name'       => 'block-theme/example-block',
     264            'viewScript' => 'file:./view.js',
     265        );
     266        $result   = register_block_script_handle( $metadata, 'viewScript' );
     267
     268        $expected_script_handle = 'block-theme-example-block-view-script';
     269        $this->assertSame( $expected_script_handle, $result );
     270    }
     271
     272    /**
    256273     * @ticket 50263
    257274     */
     
    304321            wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) )
    305322        );
     323    }
     324
     325    /**
     326     * @ticket 55513
     327     */
     328    public function test_success_register_block_style_handle_in_theme() {
     329        switch_theme( 'block-theme' );
     330
     331        $metadata = array(
     332            'file'        => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ),
     333            'name'        => 'block-theme/example-block',
     334            'editorStyle' => 'file:./editor-style.css',
     335        );
     336        $result   = register_block_style_handle( $metadata, 'editorStyle' );
     337
     338        $expected_style_handle = 'block-theme-example-block-editor-style';
     339        $this->assertSame( $expected_style_handle, $result );
     340        $this->assertSame( 'replace', wp_styles()->get_data( $expected_style_handle, 'rtl' ) );
    306341    }
    307342
Note: See TracChangeset for help on using the changeset viewer.