Make WordPress Core


Ignore:
Timestamp:
02/18/2021 01:11:18 AM (3 years ago)
Author:
peterwilsoncc
Message:

Editor: Additional tests for reusable blocks.

Ensure that subsequent renders of a reusable block will render correctly and that recursively inserting a reusable block into itself does not cause an internal server (500) error.

Props bernhard-reiter, SergeyBiryukov.
Fixes #52364.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/render-reusable.php

    r49603 r50382  
    8989    }
    9090
     91    /**
     92     * Make sure that a reusable block can be rendered twice in a row.
     93     *
     94     * @ticket 52364
     95     */
     96    public function test_render_subsequent() {
     97        $block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
     98        $output     = $block_type->render( array( 'ref' => self::$block_id ) );
     99        $output    .= $block_type->render( array( 'ref' => self::$block_id ) );
     100        $this->assertSame( '<p>Hello world!</p><p>Hello world!</p>', $output );
     101    }
     102
     103    /**
     104     * Throw a warning if blocks are recursively nested.
     105     *
     106     * @ticket 52364
     107     */
     108    public function test_recursive_render_warning() {
     109        $recursive_reusable_block = array(
     110            'ID'           => self::$block_id,
     111            'post_content' => '<!-- wp:block {"ref":' . self::$block_id . '} /-->',
     112        );
     113        wp_update_post( $recursive_reusable_block );
     114
     115        $block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
     116
     117        // The block_render method for `core/block` triggers a user warning if it
     118        // encounters a recursively nested block.
     119        $this->expectException( 'PHPUnit_Framework_Error_Warning' );
     120        $block_type->render( array( 'ref' => self::$block_id ) );
     121    }
     122
    91123    public function test_ref_empty() {
    92124        $block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
Note: See TracChangeset for help on using the changeset viewer.