Make WordPress Core


Ignore:
Timestamp:
09/26/2019 08:25:59 PM (7 years ago)
Author:
johnbillion
Message:

Themes: Add a test to ensure get_template_part() does not return a value.

This function must not be modified to return anything due to existing themes which output the return value, for example via echo get_template_part( ... ).

See #40969

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/template.php

    r45928 r46328  
    628628                $this->assertSame( "<meta name='robots' content='noindex,follow' />\n", $actual_public );
    629629        }
     630
     631        /**
     632         * @ticket 40969
     633         */
     634        function test_get_template_part_returns_nothing() {
     635                ob_start();
     636
     637                // The `get_template_part()` function must not return anything
     638                // due to themes in the wild that echo its return value.
     639                $part   = get_template_part( 'template', 'part' );
     640                $output = ob_get_clean();
     641
     642                self::assertSame( 'Template Part', trim( $output ) );
     643                self::assertSame( null, $part );
     644        }
    630645}
Note: See TracChangeset for help on using the changeset viewer.