Make WordPress Core

Ticket #55437: 55437.diff

File 55437.diff, 2.7 KB (added by SergeyBiryukov, 4 years ago)
  • src/wp-includes/block-template-utils.php

     
    503503
    504504        $template                 = new WP_Block_Template();
    505505        $template->id             = $theme . '//' . $template_file['slug'];
    506         $template->theme          = $theme;
     506        $template->theme          = ! empty( $template_file['theme'] ) ? $template_file['theme'] : $theme;
    507507        $template->content        = _inject_theme_attribute_in_block_template_content( $template_content );
    508508        $template->slug           = $template_file['slug'];
    509509        $template->source         = 'theme';
  • tests/phpunit/tests/block-template-utils.php

     
    123123                $this->assertSame( WP_TEMPLATE_PART_AREA_HEADER, $template_part->area );
    124124        }
    125125
     126        /**
     127         * Tests that _build_block_template_result_from_post() returns the correct theme
     128         * for the template when a child theme is active.
     129         *
     130         * @ticket 55437
     131         *
     132         * @covers ::_build_block_template_result_from_post
     133         */
     134        function test_build_block_template_result_from_post_with_child_theme() {
     135                switch_theme( 'block-theme-child' );
     136
     137                $template = _build_block_template_result_from_post(
     138                        self::$template_post,
     139                        'wp_template'
     140                );
     141
     142                $this->assertSame( self::TEST_THEME, $template->theme );
     143        }
     144
    126145        function test_build_block_template_result_from_file() {
    127146                $template = _build_block_template_result_from_file(
    128147                        array(
    … …  
    161180                $this->assertSame( WP_TEMPLATE_PART_AREA_HEADER, $template_part->area );
    162181        }
    163182
     183        /**
     184         * Tests that _build_block_template_result_from_file() returns the correct theme
     185         * for the template when a child theme is active.
     186         *
     187         * @ticket 55437
     188         *
     189         * @covers ::_build_block_template_result_from_file
     190         */
     191        function test_build_block_template_result_from_file_with_child_theme() {
     192                switch_theme( 'block-theme-child' );
     193
     194                $template = _build_block_template_result_from_file(
     195                        array(
     196                                'slug'  => 'single',
     197                                'path'  => __DIR__ . '/../data/templates/template.html',
     198                                'theme' => self::TEST_THEME,
     199                        ),
     200                        'wp_template'
     201                );
     202
     203                $this->assertSame( self::TEST_THEME, $template->theme );
     204        }
     205
    164206        function test_inject_theme_attribute_in_block_template_content() {
    165207                $theme                           = get_stylesheet();
    166208                $content_without_theme_attribute = '<!-- wp:template-part {"slug":"header","align":"full", "tagName":"header","className":"site-header"} /-->';