From 6b983b1d5c432b7e219d81ad3f8a17f2e383dad6 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 26 Sep 2019 20:25:59 +0000 Subject: [PATCH] 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 --- .../data/themedir1/default/template-part.php | 1 + tests/phpunit/tests/general/template.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/phpunit/data/themedir1/default/template-part.php diff --git a/tests/phpunit/data/themedir1/default/template-part.php b/tests/phpunit/data/themedir1/default/template-part.php new file mode 100644 index 0000000000..05c759fcbb --- /dev/null +++ b/tests/phpunit/data/themedir1/default/template-part.php @@ -0,0 +1 @@ +Template Part diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index fa6636170c..648e22661a 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -627,4 +627,19 @@ class Tests_General_Template extends WP_UnitTestCase { $actual_public = get_echo( 'wp_no_robots' ); $this->assertSame( "\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 ); + } }