WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/21/2021 09:30:40 AM (9 months ago)
Author:
gziolo
Message:

Editor: Shape block editor filters to work better with the Gutenberg plugin

This should allow to use new filters in the Gutenberg plugin and therefore it prevents deprecation warnings when in the debug mode.

See #52920.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/block-editor.php

    r50776 r50777  
    253253            return array( 'test/filtered-my-block' );
    254254        }
    255         function filter_block_categories_my_editor() {
    256             return array(
    257                 array(
    258                     'slug'  => 'filtered-my-category',
    259                     'title' => 'Filtered My Category',
    260                     'icon'  => null,
    261                 ),
    262             );
    263         }
    264255        function filter_block_editor_settings_my_editor( $editor_settings ) {
    265256            $editor_settings['maxUploadFileSize'] = 12345;
     
    269260
    270261        add_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor', 10, 1 );
    271         add_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor', 10, 1 );
    272262        add_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor', 10, 1 );
    273263
     
    275265
    276266        remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' );
    277         remove_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor' );
    278267        remove_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor' );
    279268
    280269        $this->assertSameSets( array( 'test/filtered-my-block' ), $settings['allowedBlockTypes'] );
    281         $this->assertSameSets(
    282             array(
    283                 array(
    284                     'slug'  => 'filtered-my-category',
    285                     'title' => 'Filtered My Category',
     270        $this->assertSame( 12345, $settings['maxUploadFileSize'] );
     271    }
     272
     273    /**
     274     * @ticket 52920
     275     */
     276    function test_get_block_editor_settings_overrides_default_settings_any_editor() {
     277        function filter_allowed_block_types_any_editor() {
     278            return array( 'test/filtered-any-block' );
     279        }
     280        function filter_block_categories_any_editor() {
     281            return array(
     282                array(
     283                    'slug'  => 'filtered-any-category',
     284                    'title' => 'Filtered Any Category',
     285                    'icon'  => null,
     286                ),
     287            );
     288        }
     289        function filter_block_editor_settings_any_editor( $editor_settings ) {
     290            $editor_settings['maxUploadFileSize'] = 54321;
     291
     292            return $editor_settings;
     293        }
     294
     295        add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor', 10, 1 );
     296        add_filter( 'block_categories_all', 'filter_block_categories_any_editor', 10, 1 );
     297        add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor', 10, 1 );
     298
     299        $settings = get_block_editor_settings( 'any-editor' );
     300
     301        remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor' );
     302        remove_filter( 'block_categories_all', 'filter_block_categories_any_editor' );
     303        remove_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor' );
     304
     305        $this->assertSameSets( array( 'test/filtered-any-block' ), $settings['allowedBlockTypes'] );
     306        $this->assertSameSets(
     307            array(
     308                array(
     309                    'slug'  => 'filtered-any-category',
     310                    'title' => 'Filtered Any Category',
    286311                    'icon'  => null,
    287312                ),
     
    289314            $settings['blockCategories']
    290315        );
    291         $this->assertSame( 12345, $settings['maxUploadFileSize'] );
     316        $this->assertSame( 54321, $settings['maxUploadFileSize'] );
    292317    }
    293318
Note: See TracChangeset for help on using the changeset viewer.