WordPress.org

Make WordPress Core

Ticket #52364: 52364.diff

File 52364.diff, 1.7 KB (added by peterwilsoncc, 8 months ago)
  • tests/phpunit/tests/blocks/render-reusable.php

    diff --git a/tests/phpunit/tests/blocks/render-reusable.php b/tests/phpunit/tests/blocks/render-reusable.php
    index 66b01b0428..eeea33b343 100644
    a b class WP_Test_Render_Reusable_Blocks extends WP_UnitTestCase { 
    8888                $this->assertSame( '<p>Hello world!</p>', $output );
    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' );
    93125                $output     = $block_type->render( array() );