Ticket #40969: 40969.8.diff
File 40969.8.diff, 5.1 KB (added by , 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 16 16 * "special". 17 17 * 18 18 * @since 1.5.0 19 * @since 5.4.0 A return value was added. 19 20 * 20 21 * @param string $name The name of the specialised header. 22 * @return void|false Void on success, false if the template does not exist. 21 23 */ 22 24 function get_header( $name = null ) { 23 25 /** … … function get_header( $name = null ) { 38 40 39 41 $templates[] = 'header.php'; 40 42 41 locate_template( $templates, true ); 43 if ( ! locate_template( $templates, true ) ) { 44 return false; 45 } 42 46 } 43 47 44 48 /** … … function get_header( $name = null ) { 51 55 * "special". 52 56 * 53 57 * @since 1.5.0 58 * @since 5.4.0 A return value was added. 54 59 * 55 60 * @param string $name The name of the specialised footer. 61 * @return void|false Void on success, false if the template does not exist. 56 62 */ 57 63 function get_footer( $name = null ) { 58 64 /** … … function get_footer( $name = null ) { 73 79 74 80 $templates[] = 'footer.php'; 75 81 76 locate_template( $templates, true ); 82 if ( ! locate_template( $templates, true ) ) { 83 return false; 84 } 77 85 } 78 86 79 87 /** … … function get_footer( $name = null ) { 86 94 * "special". 87 95 * 88 96 * @since 1.5.0 97 * @since 5.4.0 A return value was added. 89 98 * 90 99 * @param string $name The name of the specialised sidebar. 100 * @return void|false Void on success, false if the template does not exist. 91 101 */ 92 102 function get_sidebar( $name = null ) { 93 103 /** … … function get_sidebar( $name = null ) { 108 118 109 119 $templates[] = 'sidebar.php'; 110 120 111 locate_template( $templates, true ); 121 if ( ! locate_template( $templates, true ) ) { 122 return false; 123 } 112 124 } 113 125 114 126 /** … … function get_sidebar( $name = null ) { 128 140 * "special". 129 141 * 130 142 * @since 3.0.0 143 * @since 5.4.0 A return value was added. 131 144 * 132 145 * @param string $slug The slug name for the generic template. 133 146 * @param string $name The name of the specialised template. 147 * @return void|false Void on success, false if the template does not exist. 134 148 */ 135 149 function get_template_part( $slug, $name = null ) { 136 150 /** … … function get_template_part( $slug, $name = null ) { 165 179 */ 166 180 do_action( 'get_template_part', $slug, $name, $templates ); 167 181 168 locate_template( $templates, true, false ); 182 if ( ! locate_template( $templates, true, false ) ) { 183 return false; 184 } 169 185 } 170 186 171 187 /** -
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
- + 1 Footer -
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
- + 1 Header -
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
- + 1 Sidebar -
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 { 631 631 /** 632 632 * @ticket 40969 633 633 */ 634 function test_get_template_part_returns_nothing () {634 function test_get_template_part_returns_nothing_on_success() { 635 635 ob_start(); 636 636 637 637 // The `get_template_part()` function must not return anything … … class Tests_General_Template extends WP_UnitTestCase { 642 642 self::assertSame( 'Template Part', trim( $output ) ); 643 643 self::assertSame( null, $part ); 644 644 } 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 } 645 697 }