WordPress.org

Make WordPress Core

Ticket #41717: 41717.2.diff

File 41717.2.diff, 4.5 KB (added by swissspidy, 4 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 4dd0a75016..171d8b6c58 100644
    final class WP_Theme implements ArrayAccess { 
    10361036                if ( ! is_array( $post_templates ) ) {
    10371037                        $post_templates = array();
    10381038
    1039                         $files = (array) $this->get_files( 'php', 1 );
     1039                        $files = (array) $this->get_files( 'php', 1, true);
    10401040
    10411041                        foreach ( $files as $file => $full_path ) {
    10421042                                if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {
    final class WP_Theme implements ArrayAccess { 
    10911091                $post_templates = $this->get_post_templates();
    10921092                $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
    10931093
    1094                 if ( $this->parent() ) {
    1095                         $post_templates += $this->parent()->get_page_templates( $post, $post_type );
    1096                 }
    1097 
    10981094                /**
    10991095                 * Filters list of page templates for a theme.
    11001096                 *
  • new file tests/phpunit/data/themedir1/page-templates-child/subdir/template-sub-dir-post-types-child.php

    diff --git tests/phpunit/data/themedir1/page-templates-child/subdir/template-sub-dir-post-types-child.php tests/phpunit/data/themedir1/page-templates-child/subdir/template-sub-dir-post-types-child.php
    new file mode 100644
    index 0000000000..f0a688d57f
    - +  
     1<?php
     2/*
     3   Template Name: Sub Dir In A Child Theme
     4   Template Post Type: foo
     5 */
  • new file tests/phpunit/data/themedir1/page-templates-child/template-top-level-post-types-child.php

    diff --git tests/phpunit/data/themedir1/page-templates-child/template-top-level-post-types-child.php tests/phpunit/data/themedir1/page-templates-child/template-top-level-post-types-child.php
    new file mode 100644
    index 0000000000..cc1fe32da9
    - +  
     1<?php
     2/*
     3   Template Name: Top Level In A Child Theme
     4   Template Post Type: foo
     5 */
     6
  • tests/phpunit/tests/admin/includesTheme.php

    diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php
    index 223560d98d..86ec368d67 100644
    class Tests_Admin_includesTheme extends WP_UnitTestCase { 
    122122                switch_theme( $theme['Template'], $theme['Stylesheet'] );
    123123
    124124                $this->assertEqualSetsWithIndex( array(
    125                         'Top Level' => 'template-top-level-post-types.php',
    126                         'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     125                        'Top Level'                  => 'template-top-level-post-types.php',
     126                        'Sub Dir'                    => 'subdir/template-sub-dir-post-types.php',
     127                        'Top Level In A Child Theme' => 'template-top-level-post-types-child.php',
     128                        'Sub Dir In A Child Theme'   => 'subdir/template-sub-dir-post-types-child.php',
    127129                ), get_page_templates( null, 'foo' ) );
     130
    128131                $this->assertEqualSetsWithIndex( array(
    129132                        'Top Level' => 'template-top-level-post-types.php',
    130133                        'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
    131134                ), get_page_templates( null, 'post' ) );
     135
    132136                $this->assertEqualSetsWithIndex( array(
    133137                        'Top Level'                           => 'template-top-level.php',
    134138                        'Sub Dir'                             => 'subdir/template-sub-dir.php',
    135139                        'This Template Header Is On One Line' => 'template-header.php',
    136140                ), get_page_templates() );
     141
    137142                $this->assertEquals( array(), get_page_templates( null, 'bar' ) );
    138143        }
    139144
     145        /**
     146         * @ticket 41717
     147         */
     148        public function test_get_post_templates_child_theme() {
     149                $theme = wp_get_theme( 'page-templates-child' );
     150                $this->assertNotEmpty( $theme );
     151
     152                switch_theme( $theme['Template'], $theme['Stylesheet'] );
     153
     154                $post_templates = $theme->get_post_templates();
     155
     156                $this->assertEqualSetsWithIndex( array(
     157                        'template-top-level-post-types.php'            => 'Top Level',
     158                        'subdir/template-sub-dir-post-types.php'       => 'Sub Dir',
     159                        'template-top-level-post-types-child.php'      => 'Top Level In A Child Theme',
     160                        'subdir/template-sub-dir-post-types-child.php' => 'Sub Dir In A Child Theme',
     161                ), $post_templates['foo'] );
     162
     163                $this->assertEqualSetsWithIndex( array(
     164                        'template-top-level-post-types.php'      => 'Top Level',
     165                        'subdir/template-sub-dir-post-types.php' => 'Sub Dir',
     166                ), $post_templates['post'] );
     167
     168                $this->assertEqualSetsWithIndex( array(
     169                        'template-top-level.php'      => 'Top Level',
     170                        'subdir/template-sub-dir.php' => 'Sub Dir',
     171                        'template-header.php'         => 'This Template Header Is On One Line',
     172                ), $post_templates['page'] );
     173        }
     174
    140175        /**
    141176         * Test that the list of theme features pulled from the WordPress.org API returns the expected data structure.
    142177         *