Make WordPress Core


Ignore:
Timestamp:
06/21/2023 04:21:04 AM (3 years ago)
Author:
isabel_brison
Message:

Editor: add Post Content attributes to block editor settings.

Adds a new block editor setting containing the Post Content block attributes, if they exist.

Props audrasjb, spacedmonkey, jeremyfelt, mukesh27, flixos90, andrewserong.
Fixes #58534.

File:
1 edited

Legend:

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

    r55822 r55955  
    2828        $wp_rest_server = new Spy_REST_Server();
    2929        do_action( 'rest_api_init', $wp_rest_server );
     30
     31        global $post_ID;
     32        $post_ID = 1;
    3033    }
    3134
     
    3437        global $wp_rest_server;
    3538        $wp_rest_server = null;
     39        global $post_ID;
     40        $post_ID = null;
    3641        parent::tear_down();
    3742    }
     
    398403
    399404    /**
     405     * @ticket 58534
     406     */
     407    public function test_wp_get_first_block() {
     408        $block_name               = 'core/paragraph';
     409        $blocks                   = array(
     410            array(
     411                'blockName' => 'core/image',
     412            ),
     413            array(
     414                'blockName' => $block_name,
     415                'attrs'     => array(
     416                    'content' => 'Hello World!',
     417                ),
     418            ),
     419            array(
     420                'blockName' => 'core/heading',
     421            ),
     422            array(
     423                'blockName' => $block_name,
     424            ),
     425        );
     426        $blocks_with_no_paragraph = array(
     427            array(
     428                'blockName' => 'core/image',
     429            ),
     430            array(
     431                'blockName' => 'core/heading',
     432            ),
     433        );
     434
     435        $this->assertSame( $blocks[1], wp_get_first_block( $blocks, $block_name ) );
     436
     437        $this->assertSame( array(), wp_get_first_block( $blocks_with_no_paragraph, $block_name ) );
     438    }
     439
     440    /**
     441     * @ticket 58534
     442     */
     443    public function test_wp_get_post_content_block_attributes() {
     444        $attributes_with_layout = array(
     445            'layout' => array(
     446                'type' => 'constrained',
     447            ),
     448        );
     449        // With no block theme, expect an empty array.
     450        $this->assertSame( array(), wp_get_post_content_block_attributes() );
     451
     452        switch_theme( 'block-theme' );
     453
     454        $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() );
     455    }
     456
     457    /**
    400458     * @ticket 53458
    401459     */
     
    457515        // settings.spacing.customPadding
    458516        $this->assertTrue( $settings['enableCustomSpacing'] );
     517        // settings.postContentAttributes
     518        $this->assertSameSets(
     519            array(
     520                'layout' => array(
     521                    'type' => 'constrained',
     522                ),
     523            ),
     524            $settings['postContentAttributes']
     525        );
    459526
    460527        switch_theme( WP_DEFAULT_THEME );
Note: See TracChangeset for help on using the changeset viewer.