Make WordPress Core


Ignore:
Timestamp:
01/31/2024 09:09:22 AM (16 months ago)
Author:
gziolo
Message:

Editor: Add viewStyle property to block.json for frontend-only block styles

Related issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/54491.

For block scripts there was already script, viewScript and editorScript. For block styles there was only style and editorStyle. This brings the parity.

Props gaambo.
Fixes #59673.

File:
1 edited

Legend:

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

    r57068 r57493  
    157157            generate_block_asset_handle( $block_name, 'style' )
    158158        );
     159        // @ticket 59673
     160        $this->assertSame(
     161            'unit-tests-my-block-view-style',
     162            generate_block_asset_handle( $block_name, 'viewStyle' ),
     163            'asset handle for viewStyle is not generated correctly'
     164        );
    159165    }
    160166
     
    440446    public function test_success_register_block_style_handle() {
    441447        $metadata = array(
    442             'file'  => DIR_TESTDATA . '/blocks/notice/block.json',
    443             'name'  => 'unit-tests/test-block',
    444             'style' => 'file:./block.css',
     448            'file'      => DIR_TESTDATA . '/blocks/notice/block.json',
     449            'name'      => 'unit-tests/test-block',
     450            'style'     => 'file:./block.css',
     451            'viewStyle' => 'file:./block-view.css',
    445452        );
    446453        $result   = register_block_style_handle( $metadata, 'style' );
     
    453460            wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block.css' ) ),
    454461            wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) )
     462        );
     463
     464        // Test viewStyle property
     465        $result = register_block_style_handle( $metadata, 'viewStyle' );
     466        $this->assertSame( 'unit-tests-test-block-view-style', $result );
     467
     468        // @ticket 59673
     469        $this->assertSame(
     470            wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block-view.css' ) ),
     471            wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-view-style', 'path' ) ),
     472            'viewStyle asset path is not correct'
    455473        );
    456474
     
    838856            $result->style_handles
    839857        );
     858        // @ticket 59673
     859        $this->assertSameSets(
     860            array( 'tests-notice-view-style' ),
     861            $result->view_style_handles,
     862            'parsed view_style_handles is not correct'
     863        );
    840864
    841865        // @ticket 50328
     
    843867            wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block.css' ) ),
    844868            wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) )
     869        );
     870
     871        // @ticket 59673
     872        $this->assertSame(
     873            wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block-view.css' ) ),
     874            wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-view-style', 'path' ) ),
     875            'viewStyle asset path is not correct'
    845876        );
    846877
Note: See TracChangeset for help on using the changeset viewer.