WordPress.org

Make WordPress Core

Ticket #41717: 41717.diff

File 41717.diff, 4.8 KB (added by birgire, 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 30e9226..9eb4fda 100644
    final class WP_Theme implements ArrayAccess { 
    10111011                if ( ! is_array( $post_templates ) ) {
    10121012                        $post_templates = array();
    10131013
    1014                         $files = (array) $this->get_files( 'php', 1 );
     1014                        $files = (array) $this->get_files( 'php', 1, true);
    10151015
    10161016                        foreach ( $files as $file => $full_path ) {
    10171017                                if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {
    final class WP_Theme implements ArrayAccess { 
    10661066                $post_templates = $this->get_post_templates();
    10671067                $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
    10681068
    1069                 if ( $this->parent() ) {
    1070                         $post_templates += $this->parent()->get_page_templates( $post, $post_type );
    1071                 }
    1072 
    10731069                /**
    10741070                 * Filters list of page templates for a theme.
    10751071                 *
  • new file tests/phpunit/data/themedir1/page-templates-child/subdir/template-sub-dir-post-types-41717-child.php

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

    diff --git tests/phpunit/data/themedir1/page-templates-child/template-top-level-post-types-41717-child.php tests/phpunit/data/themedir1/page-templates-child/template-top-level-post-types-41717-child.php
    new file mode 100644
    index 0000000..685312e
    - +  
     1<?php
     2/*
     3   Template Name: Top Level In A Child Theme
     4   Template Post Type: dog
     5 */
     6
  • new file tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types-41717.php

    diff --git tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types-41717.php tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types-41717.php
    new file mode 100644
    index 0000000..3ae656d
    - +  
     1<?php
     2/*
     3   Template Name: Sub Dir
     4   Template Post Type: dog, cat
     5 */
  • new file tests/phpunit/data/themedir1/page-templates/template-top-level-post-types-41717.php

    diff --git tests/phpunit/data/themedir1/page-templates/template-top-level-post-types-41717.php tests/phpunit/data/themedir1/page-templates/template-top-level-post-types-41717.php
    new file mode 100644
    index 0000000..b4e0514
    - +  
     1<?php
     2/*
     3   Template Name: Top Level
     4   Template Post Type: dog, cat
     5 */
  • tests/phpunit/tests/admin/includesTheme.php

    diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php
    index 223560d..7ff4aed 100644
    class Tests_Admin_includesTheme extends WP_UnitTestCase { 
    138138        }
    139139
    140140        /**
     141         * @ticket 41717
     142         */
     143        function test_get_post_templates_method_with_child_theme_activated() {
     144                $theme = wp_get_theme( 'page-templates-child' );
     145                $this->assertNotEmpty( $theme );
     146
     147                switch_theme( $theme['Template'], $theme['Stylesheet'] );
     148
     149                $post_templates = $theme->get_post_templates();
     150
     151                $this->assertEqualSetsWithIndex( array(
     152                        'template-top-level-post-types-41717.php'            => 'Top Level',
     153                        'subdir/template-sub-dir-post-types-41717.php'       => 'Sub Dir',
     154                        'template-top-level-post-types-41717-child.php'      => 'Top Level In A Child Theme',
     155                        'subdir/template-sub-dir-post-types-41717-child.php' => 'Sub Dir In Child Theme',
     156                ), $post_templates['dog'] );
     157
     158                $this->assertEqualSetsWithIndex( array(
     159                        'template-top-level-post-types-41717.php'      => 'Top Level',
     160                        'subdir/template-sub-dir-post-types-41717.php' => 'Sub Dir',
     161                ), $post_templates['cat'] );
     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['foo'] );
     167
     168                $this->assertEqualSetsWithIndex( array(
     169                        'template-top-level-post-types.php'      => 'Top Level',
     170                        'subdir/template-sub-dir-post-types.php' => 'Sub Dir',
     171                ), $post_templates['post'] );
     172
     173                $this->assertEqualSetsWithIndex( array(
     174                        'template-top-level.php'      => 'Top Level',
     175                        'subdir/template-sub-dir.php' => 'Sub Dir',
     176                        'template-header.php'         => 'This Template Header Is On One Line',
     177                ), $post_templates['page'] );
     178
     179        }
     180
     181        /**
    141182         * Test that the list of theme features pulled from the WordPress.org API returns the expected data structure.
    142183         *
    143184         * Differences in the structure can also trigger failure by causing PHP notices/warnings.