Make WordPress Core

Ticket #40969: 40969.8.diff

File 40969.8.diff, 5.1 KB (added by tferry, 5 years ago)
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 82c138cef7..ef2bf442ef 100644
    a b  
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 5.4.0 A return value was added.
    1920 *
    2021 * @param string $name The name of the specialised header.
     22 * @return void|false Void on success, false if the template does not exist.
    2123 */
    2224function get_header( $name = null ) {
    2325        /**
    function get_header( $name = null ) { 
    3840
    3941        $templates[] = 'header.php';
    4042
    41         locate_template( $templates, true );
     43        if ( ! locate_template( $templates, true ) ) {
     44                return false;
     45        }
    4246}
    4347
    4448/**
    function get_header( $name = null ) { 
    5155 * "special".
    5256 *
    5357 * @since 1.5.0
     58 * @since 5.4.0 A return value was added.
    5459 *
    5560 * @param string $name The name of the specialised footer.
     61 * @return void|false Void on success, false if the template does not exist.
    5662 */
    5763function get_footer( $name = null ) {
    5864        /**
    function get_footer( $name = null ) { 
    7379
    7480        $templates[] = 'footer.php';
    7581
    76         locate_template( $templates, true );
     82        if ( ! locate_template( $templates, true ) ) {
     83                return false;
     84        }
    7785}
    7886
    7987/**
    function get_footer( $name = null ) { 
    8694 * "special".
    8795 *
    8896 * @since 1.5.0
     97 * @since 5.4.0 A return value was added.
    8998 *
    9099 * @param string $name The name of the specialised sidebar.
     100 * @return void|false Void on success, false if the template does not exist.
    91101 */
    92102function get_sidebar( $name = null ) {
    93103        /**
    function get_sidebar( $name = null ) { 
    108118
    109119        $templates[] = 'sidebar.php';
    110120
    111         locate_template( $templates, true );
     121        if ( ! locate_template( $templates, true ) ) {
     122                return false;
     123        }
    112124}
    113125
    114126/**
    function get_sidebar( $name = null ) { 
    128140 * "special".
    129141 *
    130142 * @since 3.0.0
     143 * @since 5.4.0 A return value was added.
    131144 *
    132145 * @param string $slug The slug name for the generic template.
    133146 * @param string $name The name of the specialised template.
     147 * @return void|false Void on success, false if the template does not exist.
    134148 */
    135149function get_template_part( $slug, $name = null ) {
    136150        /**
    function get_template_part( $slug, $name = null ) { 
    165179         */
    166180        do_action( 'get_template_part', $slug, $name, $templates );
    167181
    168         locate_template( $templates, true, false );
     182        if ( ! locate_template( $templates, true, false ) ) {
     183                return false;
     184        }
    169185}
    170186
    171187/**
  • new file tests/phpunit/data/themedir1/default/footer.php

    diff --git a/tests/phpunit/data/themedir1/default/footer.php b/tests/phpunit/data/themedir1/default/footer.php
    new file mode 100644
    index 0000000000..e36f7f7118
    - +  
     1Footer
  • new file tests/phpunit/data/themedir1/default/header.php

    diff --git a/tests/phpunit/data/themedir1/default/header.php b/tests/phpunit/data/themedir1/default/header.php
    new file mode 100644
    index 0000000000..74fcd1a347
    - +  
     1Header
  • new file tests/phpunit/data/themedir1/default/sidebar.php

    diff --git a/tests/phpunit/data/themedir1/default/sidebar.php b/tests/phpunit/data/themedir1/default/sidebar.php
    new file mode 100644
    index 0000000000..96438493b6
    - +  
     1Sidebar
  • tests/phpunit/tests/general/template.php

    diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php
    index 170a86d9f9..a3cf0fdda5 100644
    a b class Tests_General_Template extends WP_UnitTestCase { 
    631631        /**
    632632         * @ticket 40969
    633633         */
    634         function test_get_template_part_returns_nothing() {
     634        function test_get_template_part_returns_nothing_on_success() {
    635635                ob_start();
    636636
    637637                // The `get_template_part()` function must not return anything
    class Tests_General_Template extends WP_UnitTestCase { 
    642642                self::assertSame( 'Template Part', trim( $output ) );
    643643                self::assertSame( null, $part );
    644644        }
     645
     646        /**
     647         * @ticket 40969
     648         */
     649        function test_get_template_part_returns_false_on_failure() {
     650                self::assertSame( false, get_template_part( 'non-existing-template' ) );
     651        }
     652
     653        /**
     654         * @ticket 40969
     655         */
     656        function test_get_header_returns_nothing_on_success() {
     657                ob_start();
     658
     659                // The `get_header()` function must not return anything
     660                // due to themes in the wild that may echo its return value.
     661                $part   = get_header();
     662                $output = ob_get_clean();
     663
     664                self::assertSame( 'Header', trim( $output ) );
     665                self::assertSame( null, $part );
     666        }
     667
     668        /**
     669         * @ticket 40969
     670         */
     671        function test_get_footer_returns_nothing_on_success() {
     672                ob_start();
     673
     674                // The `get_footer()` function must not return anything
     675                // due to themes in the wild that may echo its return value.
     676                $part   = get_footer();
     677                $output = ob_get_clean();
     678
     679                self::assertSame( 'Footer', trim( $output ) );
     680                self::assertSame( null, $part );
     681        }
     682
     683        /**
     684         * @ticket 40969
     685         */
     686        function test_get_sidebar_returns_nothing_on_success() {
     687                ob_start();
     688
     689                // The `get_sidebar()` function must not return anything
     690                // due to themes in the wild that may echo its return value.
     691                $part   = get_sidebar();
     692                $output = ob_get_clean();
     693
     694                self::assertSame( 'Sidebar', trim( $output ) );
     695                self::assertSame( null, $part );
     696        }
    645697}