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


git-svn-id: https://develop.svn.wordpress.org/trunk@46328 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2019-09-26 20:25:59 +00:00
parent c61471a495
commit 6b983b1d5c
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1 @@
Template Part

View File

@ -627,4 +627,19 @@ class Tests_General_Template extends WP_UnitTestCase {
$actual_public = get_echo( 'wp_no_robots' );
$this->assertSame( "<meta name='robots' content='noindex,follow' />\n", $actual_public );
}
/**
* @ticket 40969
*/
function test_get_template_part_returns_nothing() {
ob_start();
// The `get_template_part()` function must not return anything
// due to themes in the wild that echo its return value.
$part = get_template_part( 'template', 'part' );
$output = ob_get_clean();
self::assertSame( 'Template Part', trim( $output ) );
self::assertSame( null, $part );
}
}