WordPress.org

Make WordPress Core

Ticket #38766: 38766.2.diff

File 38766.2.diff, 2.6 KB (added by peterwilsoncc, 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 8b3661a..0053fe9 100644
    final class WP_Theme implements ArrayAccess { 
    10331033                                }
    10341034
    10351035                                $types = array( 'page' );
    1036                                 if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) {
     1036                                if ( preg_match( '|Template Post Type:(.*)\.?\s*$|miU', file_get_contents( $full_path ), $type ) ) {
    10371037                                        $types = explode( ',', _cleanup_header_comment( $type[1] ) );
    10381038                                }
    10391039
  • new file tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php

    diff --git tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php
    new file mode 100644
    index 0000000..2b68671
    - +  
     1<?php
     2/*
     3   Template Name: No Trailing Period
     4   Template Post Type: period, full-stop
     5 */
  • new file tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php

    diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php
    new file mode 100644
    index 0000000..594b677
    - +  
     1<?php
     2/*
     3   Template Name: Trailing Period.
     4   Template Post Type: period, full-stop.
     5
     6   Text following the meaningful line to the modifier behaves as expected.
     7 */
  • tests/phpunit/tests/admin/includesTheme.php

    diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php
    index 5319006..6a11a7a 100644
    class Tests_Admin_includesTheme extends WP_UnitTestCase { 
    8787        }
    8888
    8989        /**
     90         * @ticket 38766
     91         */
     92        function test_page_templates_for_post_types_with_trailing_periods() {
     93                $theme = wp_get_theme( 'page-templates' );
     94                $this->assertNotEmpty( $theme );
     95
     96                switch_theme( $theme['Template'], $theme['Stylesheet'] );
     97
     98                $this->assertEqualSetsWithIndex( array(
     99                        'No Trailing Period' => '38766/no-trailing-period-post-types.php',
     100                        'Trailing Period.' => '38766/trailing-period-post-types.php',
     101                ), get_page_templates( null, 'period' ) );
     102                $this->assertEqualSetsWithIndex( array(
     103                        'No Trailing Period' => '38766/no-trailing-period-post-types.php',
     104                        'Trailing Period.' => '38766/trailing-period-post-types.php',
     105                ), get_page_templates( null, 'full-stop' ) );
     106        }
     107
     108        /**
    90109         * @ticket 38696
    91110         */
    92111        function test_page_templates_child_theme() {