WordPress.org

Make WordPress Core

Ticket #40820: 40820.2.diff

File 40820.2.diff, 2.7 KB (added by swissspidy, 3 years ago)
  • src/wp-includes/class-wp-theme.php

    diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
    index 77b5742a49..5a691b72db 100644
    final class WP_Theme implements ArrayAccess { 
    267267                        }
    268268                }
    269269
     270                if ( ! $this->template && $this->stylesheet === $this->headers['Template'] ) {
     271                        /* translators: %s: Template */
     272                        $this->errors = new WP_Error( 'theme_child_invalid', sprintf( __( 'The theme defines itself as its parent theme. Please check the "%s" header.' ), 'Template' ) );
     273                        $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
     274
     275                        return;
     276                }
     277
    270278                // (If template is set from cache [and there are no errors], we know it's good.)
    271279                if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) {
    272280                        $this->template = $this->stylesheet;
  • tests/phpunit/tests/theme/WPTheme.php

    diff --git tests/phpunit/tests/theme/WPTheme.php tests/phpunit/tests/theme/WPTheme.php
    index da7374e090..b0886e51d8 100644
    class Tests_Theme_WPTheme extends WP_UnitTestCase { 
    140140                $this->assertFalse( $theme->display( 'Tags' ) );
    141141        }
    142142
     143        /**
     144         * @ticket 40820
     145         */
     146        function test_child_theme_with_itself_as_parent_should_appear_as_broken() {
     147                $theme = new WP_Theme( 'child-parent-itself', $this->theme_root );
     148                $errors = $theme->errors();
     149                $this->assertWPError( $errors );
     150                $this->assertEquals( 'theme_child_invalid', $errors->get_error_code() );
     151        }
     152
    143153
    144154        /**
    145155         * Enable a single theme on a network.
  • tests/phpunit/tests/theme/themeDir.php

    diff --git tests/phpunit/tests/theme/themeDir.php tests/phpunit/tests/theme/themeDir.php
    index ef6e64c210..67301429ef 100644
    class Tests_Theme_ThemeDir extends WP_UnitTestCase { 
    175175         * @expectedDeprecated get_broken_themes
    176176         */
    177177        function test_broken_themes() {
    178                 $themes = get_themes();
    179                 $expected = array('broken-theme' => array('Name' => 'broken-theme', 'Title' => 'broken-theme', 'Description' => __('Stylesheet is missing.')));
     178                $themes   = get_themes();
     179
     180                $expected = array(
     181                        'broken-theme'           => array(
     182                                'Name'        => 'broken-theme',
     183                                'Title'       => 'broken-theme',
     184                                'Description' => __( 'Stylesheet is missing.' ),
     185                        ),
     186                        'Child and Parent Theme' => array(
     187                                'Name'        => 'Child and Parent Theme',
     188                                'Title'       => 'Child and Parent Theme',
     189                                'Description' => sprintf( __( 'The theme defines itself as its parent theme. Please check the "%s" header.' ), 'Template' ),
     190                        ),
     191                );
    180192
    181193                $this->assertEquals($expected, get_broken_themes() );
    182194        }