Ticket #18375: 18375.diff
File 18375.diff, 24.7 KB (added by , 9 years ago) |
---|
-
src/wp-admin/edit-form-advanced.php
diff --git src/wp-admin/edit-form-advanced.php src/wp-admin/edit-form-advanced.php index 75c3cef..0a1f886 100644
foreach ( get_object_taxonomies( $post ) as $tax_name ) { 259 259 add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) ); 260 260 } 261 261 262 if ( post_type_supports($post_type, 'page-attributes') ) 263 add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); 262 if ( post_type_supports( $post_type, 'page-attributes' ) ) { 263 add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' ); 264 } 264 265 265 266 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) 266 267 add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low'); -
src/wp-admin/includes/class-wp-posts-list-table.php
diff --git src/wp-admin/includes/class-wp-posts-list-table.php src/wp-admin/includes/class-wp-posts-list-table.php index 7ef790e..08a6730 100644
class WP_Posts_List_Table extends WP_List_Table { 1523 1523 </label> 1524 1524 1525 1525 <?php endif; // !$bulk 1526 1527 if ( 'page' === $screen->post_type ) :1528 1526 ?> 1529 1527 1530 1528 <label> … … class WP_Posts_List_Table extends WP_List_Table { 1538 1536 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' ); 1539 1537 ?> 1540 1538 <option value="default"><?php echo esc_html( $default_title ); ?></option> 1541 <?php page_template_dropdown( ) ?>1539 <?php page_template_dropdown( $post->page_template, $screen->post_type ) ?> 1542 1540 </select> 1543 1541 </label> 1544 1542 1545 1543 <?php 1546 endif; // page post_type1547 1544 endif; // page-attributes 1548 1545 ?> 1549 1546 -
src/wp-admin/includes/meta-boxes.php
diff --git src/wp-admin/includes/meta-boxes.php src/wp-admin/includes/meta-boxes.php index 2d12faf..5915777 100644
function post_revisions_meta_box( $post ) { 785 785 * @param object $post 786 786 */ 787 787 function page_attributes_meta_box($post) { 788 $post_type_object = get_post_type_object($post->post_type); 789 if ( $post_type_object->hierarchical ) { 788 if ( is_post_type_hierarchical( $post->post_type ) ) { 790 789 $dropdown_args = array( 791 790 'post_type' => $post->post_type, 792 791 'exclude_tree' => $post->ID, … … function page_attributes_meta_box($post) { 817 816 <?php 818 817 } // end empty pages check 819 818 } // end hierarchical check. 820 if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) { 821 $template = !empty($post->page_template) ? $post->page_template : false; 819 820 if ( 0 < count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) { 821 $template = ! empty( $post->page_template ) ? $post->page_template : false; 822 822 ?> 823 823 <p><strong><?php _e('Template') ?></strong><?php 824 824 /** … … function page_attributes_meta_box($post) { 832 832 */ 833 833 do_action( 'page_attributes_meta_box_template', $template, $post ); 834 834 ?></p> 835 <label class="screen-reader-text" for="page_template"><?php _e(' PageTemplate') ?></label><select name="page_template" id="page_template">835 <label class="screen-reader-text" for="page_template"><?php _e('Template') ?></label><select name="page_template" id="page_template"> 836 836 <?php 837 837 /** 838 838 * Filters the title of the default page template displayed in the drop-down. … … function page_attributes_meta_box($post) { 846 846 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' ); 847 847 ?> 848 848 <option value="default"><?php echo esc_html( $default_title ); ?></option> 849 <?php page_template_dropdown( $template); ?>849 <?php page_template_dropdown( $template, $post->post_type ); ?> 850 850 </select> 851 851 <?php 852 852 } ?> -
src/wp-admin/includes/template.php
diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php index 4eac951..2a75523 100644
function get_inline_data($post) { 293 293 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> 294 294 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; 295 295 296 if ( $post_type_object->hierarchical ) 296 if ( $post_type_object->hierarchical ) { 297 297 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 298 } 298 299 299 if ( $post->post_type == 'page' ) 300 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 300 echo '<div class="page_template">' . esc_html( $post->page_template ) . '</div>'; 301 301 302 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) 302 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { 303 303 echo '<div class="menu_order">' . $post->menu_order . '</div>'; 304 } 304 305 305 306 $taxonomy_names = get_object_taxonomies( $post->post_type ); 306 307 foreach ( $taxonomy_names as $taxonomy_name) { … … function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 761 762 * Print out option HTML elements for the page templates drop-down. 762 763 * 763 764 * @since 1.5.0 765 * @since 4.7.0 Added the `$post_type` parameter. 764 766 * 765 * @param string $default Optional. The template file name. Default empty. 767 * @param string $default Optional. The template file name. Default empty. 768 * @param string $post_type Optional. Post type to get templates for. Default 'post'. 766 769 */ 767 function page_template_dropdown( $default = '' ) {768 $templates = get_page_templates( get_post());770 function page_template_dropdown( $default = '', $post_type = 'page' ) { 771 $templates = get_page_templates( null, $post_type ); 769 772 ksort( $templates ); 770 773 foreach ( array_keys( $templates ) as $template ) { 771 774 $selected = selected( $default, $templates[ $template ], false ); -
src/wp-admin/includes/theme.php
diff --git src/wp-admin/includes/theme.php src/wp-admin/includes/theme.php index 95aaec1..905e1be 100644
function delete_theme($stylesheet, $redirect = '') { 102 102 * Get the Page Templates available in this theme 103 103 * 104 104 * @since 1.5.0 105 * @since 4.7.0 Added the `$post_type` parameter. 105 106 * 106 * @param WP_Post|null $post Optional. The post being edited, provided for context. 107 * @param WP_Post|null $post Optional. The post being edited, provided for context. 108 * @param string $post_type Optional. Post type to get the templates for. Default 'page'. 107 109 * @return array Key is the template name, value is the filename of the template 108 110 */ 109 function get_page_templates( $post = null ) {110 return array_flip( wp_get_theme()->get_page_templates( $post ) );111 function get_page_templates( $post = null, $post_type = 'page' ) { 112 return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); 111 113 } 112 114 113 115 /** -
src/wp-includes/class-wp-post.php
diff --git src/wp-includes/class-wp-post.php src/wp-includes/class-wp-post.php index a21776f..c966934 100644
final class WP_Post { 254 254 return true; 255 255 256 256 if ( 'page_template' == $key ) 257 return ( 'page' == $this->post_type );257 return true; 258 258 259 259 if ( 'post_category' == $key ) 260 260 return true; -
src/wp-includes/class-wp-theme.php
diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php index 40af39d..80f8362 100644
final class WP_Theme implements ArrayAccess { 1005 1005 } 1006 1006 1007 1007 /** 1008 * Returns the theme's p agetemplates.1008 * Returns the theme's post templates. 1009 1009 * 1010 * @since 3.4.01010 * @since 4.7.0 1011 1011 * @access public 1012 1012 * 1013 * @ param WP_Post|null $post Optional. The post being edited, provided for context.1014 * @return array Array of page templates, keyed by filename,with the value of the translated header name.1013 * @return array Array of page templates, keyed by filename and post type, 1014 * with the value of the translated header name. 1015 1015 */ 1016 public function get_p age_templates( $post = null) {1016 public function get_post_templates() { 1017 1017 // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. 1018 if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) 1018 if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) { 1019 1019 return array(); 1020 } 1020 1021 1021 $p age_templates = $this->cache_get( 'page_templates' );1022 $post_templates = $this->cache_get( 'post_templates' ); 1022 1023 1023 if ( ! is_array( $p age_templates ) ) {1024 $p age_templates = array();1024 if ( ! is_array( $post_templates ) ) { 1025 $post_templates = array(); 1025 1026 1026 1027 $files = (array) $this->get_files( 'php', 1 ); 1027 1028 1028 1029 foreach ( $files as $file => $full_path ) { 1029 if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) 1030 if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { 1030 1031 continue; 1031 $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); 1032 } 1033 1034 $types = array( 'page' ); 1035 if ( preg_match( '|Template Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) { 1036 $types = explode( ',', _cleanup_header_comment( $type[1] ) ); 1037 } 1038 1039 foreach ( $types as $type ) { 1040 $type = trim( $type ); 1041 if ( ! isset( $post_templates[ $type ] ) ) { 1042 $post_templates[ $type ] = array(); 1043 } 1044 1045 $post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] ); 1046 } 1032 1047 } 1033 1048 1034 $this->cache_add( 'page_templates', $p age_templates );1049 $this->cache_add( 'page_templates', $post_templates ); 1035 1050 } 1036 1051 1037 1052 if ( $this->load_textdomain() ) { 1038 foreach ( $page_templates as &$page_template ) { 1039 $page_template = $this->translate_header( 'Template Name', $page_template ); 1053 foreach ( $post_templates as &$post_type ) { 1054 foreach ( $post_type as &$post_template ) { 1055 $post_template = $this->translate_header( 'Template Name', $post_template ); 1056 } 1040 1057 } 1041 1058 } 1042 1059 1043 if ( $this->parent() ) 1044 $page_templates += $this->parent()->get_page_templates( $post ); 1060 return $post_templates; 1061 } 1062 1063 /** 1064 * Returns the theme's post templates for a given post type. 1065 * 1066 * @since 3.4.0 1067 * @since 4.7.0 Added the `$post_type` parameter. 1068 * @access public 1069 * 1070 * @param WP_Post|null $post Optional. The post being edited, provided for context. 1071 * @param string $post_type Optional. Post type to get the templates for. Default 'page'. 1072 * If a post is provided, its post type is used. 1073 * @return array Array of page templates, keyed by filename, with the value of the translated header name. 1074 */ 1075 public function get_page_templates( $post = null, $post_type = 'page' ) { 1076 if ( $post ) { 1077 $post_type = get_post_type( $post ); 1078 } 1079 1080 $post_templates = $this->get_post_templates(); 1081 $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array(); 1082 1083 if ( $this->parent() ) { 1084 $post_templates += $this->parent()->get_page_templates( $post ); 1085 } 1045 1086 1046 1087 /** 1047 1088 * Filters list of page templates for a theme. 1048 1089 * 1049 1090 * @since 3.9.0 1050 1091 * @since 4.4.0 Converted to allow complete control over the `$page_templates` array. 1092 * @since 4.7.0 Added the `$post_type` parameter. 1051 1093 * 1052 * @param array $p age_templates Array of page templates. Keys are filenames,1094 * @param array $post_templates Array of page templates. Keys are filenames, 1053 1095 * values are translated names. 1054 1096 * @param WP_Theme $this The theme object. 1055 1097 * @param WP_Post|null $post The post being edited, provided for context, or null. 1098 * @param string $post_type Post type to get the templates for. 1056 1099 */ 1057 return (array) apply_filters( 'theme_page_templates', $p age_templates, $this, $post);1100 return (array) apply_filters( 'theme_page_templates', $post_templates, $this, $post, $post_type ); 1058 1101 } 1059 1102 1060 1103 /** -
src/wp-includes/post-template.php
diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php index 0c1d1e4..94f6e5d 100644
function get_the_password_form( $post = 0 ) { 1613 1613 * 1614 1614 * @since 2.5.0 1615 1615 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates. 1616 * @since 4.7.0 Now supports any post type, not just pages. 1616 1617 * 1617 1618 * @param string|array $template The specific template name or array of templates to match. 1618 1619 * @return bool True on success, false on failure. 1619 1620 */ 1620 1621 function is_page_template( $template = '' ) { 1621 if ( ! is_page() )1622 return false;1623 1624 1622 $page_template = get_page_template_slug( get_queried_object_id() ); 1625 1623 1626 1624 if ( empty( $template ) ) … … function is_page_template( $template = '' ) { 1641 1639 } 1642 1640 1643 1641 /** 1644 * Get the specific template name for a page.1642 * Get the specific template name for a given post. 1645 1643 * 1646 1644 * @since 3.4.0 1645 * @since 4.7.0 Now supports all post types. 1647 1646 * 1648 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.1647 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 1649 1648 * @return string|false Page template filename. Returns an empty string when the default page template 1650 * is in use. Returns false if the post is not a page.1649 * is in use. Returns false if the post does not exist. 1651 1650 */ 1652 function get_page_template_slug( $post_id = null ) { 1653 $post = get_post( $post_id ); 1654 if ( ! $post || 'page' != $post->post_type ) 1651 function get_page_template_slug( $post = null ) { 1652 $post = get_post( $post ); 1653 1654 if ( ! $post ) { 1655 1655 return false; 1656 } 1657 1656 1658 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 1657 if ( ! $template || 'default' == $template ) 1659 1660 if ( ! $template || 'default' == $template ) { 1658 1661 return ''; 1662 } 1663 1659 1664 return $template; 1660 1665 } 1661 1666 -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index ced823c..f581017 100644
function _post_type_meta_capabilities( $capabilities = null ) { 1242 1242 * post types. Default is 'Parent Page:'. 1243 1243 * - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'. 1244 1244 * - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'. 1245 * - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'. 1245 1246 * - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'. 1246 1247 * - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' / 1247 1248 * 'Uploaded to this page'. … … function _post_type_meta_capabilities( $capabilities = null ) { 1267 1268 * @since 4.4.0 Added the `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`, 1268 1269 * `items_list_navigation`, and `items_list` labels. 1269 1270 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. 1271 * @since 4.7.0 Added the `attributes` label. 1270 1272 * 1271 1273 * @access private 1272 1274 * … … function get_post_type_labels( $post_type_object ) { 1288 1290 'parent_item_colon' => array( null, __('Parent Page:') ), 1289 1291 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), 1290 1292 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 1293 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), 1291 1294 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 1292 1295 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), 1293 1296 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ), … … function wp_insert_post( $postarr, $wp_error = false ) { 3307 3310 3308 3311 $post = get_post( $post_ID ); 3309 3312 3310 if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type']) {3313 if ( ! empty( $postarr['page_template'] ) ) { 3311 3314 $post->page_template = $postarr['page_template']; 3312 3315 $page_templates = wp_get_theme()->get_page_templates( $post ); 3313 3316 if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { -
src/wp-includes/template.php
diff --git src/wp-includes/template.php src/wp-includes/template.php index 946732f..120e698 100644
function get_single_template() { 432 432 $templates = array(); 433 433 434 434 if ( ! empty( $object->post_type ) ) { 435 $template = get_page_template_slug( $object ); 436 if ( $template && 0 === validate_file( $template ) ) { 437 $templates[] = $template; 438 } 435 439 436 440 $name_decoded = urldecode( $object->post_name ); 437 441 if ( $name_decoded !== $object->post_name ) { -
new file tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php
diff --git tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php new file mode 100644 index 0000000..7f96d18
- + 1 <?php 2 /* 3 Template Name: Sub Dir 4 Template Type: post, foo 5 */ -
new file tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php
diff --git tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php new file mode 100644 index 0000000..19ece9e
- + 1 <?php 2 /* 3 Template Name: Top Level 4 Template Type: post, foo 5 */ -
tests/phpunit/tests/admin/includesTheme.php
diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php index 382c6bb..ba76bf1 100644
class Tests_Admin_includesTheme extends WP_UnitTestCase { 48 48 49 49 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 50 50 51 $t emplates = get_page_templates();52 $this->assertCount( 3, $templates );53 $this->assertEquals( "template-top-level.php", $templates['Top Level'] );54 $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );55 $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line']);51 $this->assertEqualSetsWithIndex( array( 52 'Top Level' => 'template-top-level.php', 53 'Sub Dir' => 'subdir/template-sub-dir.php', 54 'This Template Header Is On One Line' => 'template-header.php', 55 ), get_page_templates() ); 56 56 57 57 $theme = wp_get_theme( 'page-templates' ); 58 58 $this->assertNotEmpty( $theme ); 59 59 60 60 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 61 61 62 $templates = get_page_templates(); 63 $this->assertCount( 3, $templates ); 64 $this->assertEquals( "template-top-level.php", $templates['Top Level'] ); 65 $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] ); 66 $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] ); 62 $this->assertEqualSetsWithIndex( array( 63 'Top Level' => 'template-top-level.php', 64 'Sub Dir' => 'subdir/template-sub-dir.php', 65 'This Template Header Is On One Line' => 'template-header.php', 66 ), get_page_templates() ); 67 } 68 69 /** 70 * @ticket 18375 71 */ 72 function test_page_templates_different_post_types() { 73 $theme = wp_get_theme( 'page-templates' ); 74 $this->assertNotEmpty( $theme ); 75 76 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 77 78 $this->assertEqualSetsWithIndex( array( 79 'Top Level' => 'template-top-level-post-types.php', 80 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', 81 ), get_page_templates( null, 'foo' ) ); 82 $this->assertEqualSetsWithIndex( array( 83 'Top Level' => 'template-top-level-post-types.php', 84 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', 85 ), get_page_templates( null, 'post' ) ); 86 $this->assertEquals( array(), get_page_templates( null, 'bar' ) ); 67 87 } 68 88 } -
tests/phpunit/tests/post/objects.php
diff --git tests/phpunit/tests/post/objects.php tests/phpunit/tests/post/objects.php index 5ad92c6..fb376a2 100644
class Tests_Post_Objects extends WP_UnitTestCase { 134 134 $this->assertEquals( array( 'Bar', 'Baz', 'Foo' ), $post['tags_input'] ); 135 135 } 136 136 137 /** 138 * @ticket 18375 139 */ 137 140 function test_get_page_template_property() { 138 141 $post_id = self::factory()->post->create(); 139 142 $post = get_post( $post_id ); … … class Tests_Post_Objects extends WP_UnitTestCase { 145 148 update_post_meta( $post_id, '_wp_page_template', 'foo.php' ); 146 149 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 147 150 $this->assertEquals( 'foo.php', $template ); 148 // The post is not a page so the template is still empty149 $this->assertEquals( '', $post->page_template );150 151 // Now the post is a page and should retrieve the template152 wp_update_post( array( 'ID' => $post->ID, 'post_type' => 'page' ) );153 $post = get_post( $post_id );154 151 $this->assertEquals( $template, $post->page_template ); 155 152 } 156 153 -
tests/phpunit/tests/post/template.php
diff --git tests/phpunit/tests/post/template.php tests/phpunit/tests/post/template.php index ac5958d..062b04a 100644
NO; 271 271 272 272 /** 273 273 * @ticket 31389 274 * @ticket 18375 274 275 */ 275 276 public function test_get_page_template_slug_non_page() { 276 $post_id = self::factory()->post->create( array( 277 'post_type' => 'post', 278 ) ); 277 $post_id = self::factory()->post->create(); 278 279 $this->assertEquals( '', get_page_template_slug( $post_id ) ); 280 281 update_post_meta( $post_id, '_wp_page_template', 'default' ); 279 282 280 $this->assertFalse( get_page_template_slug( $post_id ) ); 283 $this->assertEquals( '', get_page_template_slug( $post_id ) ); 284 285 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 286 $this->assertEquals( 'example.php', get_page_template_slug( $post_id ) ); 287 } 288 289 /** 290 * @ticket 18375 291 */ 292 public function test_get_page_template_slug_non_page_from_loop() { 293 $post_id = self::factory()->post->create(); 294 295 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 281 296 282 297 $this->go_to( get_permalink( $post_id ) ); 283 $this->assertFalse( get_page_template_slug() ); 298 299 $this->assertEquals( 'example.php', get_page_template_slug() ); 284 300 } 285 301 286 302 /** -
tests/phpunit/tests/query/conditionals.php
diff --git tests/phpunit/tests/query/conditionals.php tests/phpunit/tests/query/conditionals.php index 21963c7..debd18d 100644
class Tests_Query_Conditionals extends WP_UnitTestCase { 1044 1044 } 1045 1045 1046 1046 /** 1047 * @ticket 18375 1048 */ 1049 function test_is_page_template_other_post_type() { 1050 $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); 1051 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 1052 $this->go_to( get_post_permalink( $post_id ) ); 1053 $this->assertFalse( is_page_template( array( 'test.php' ) ) ); 1054 $this->assertTrue( is_page_template( array( 'test.php', 'example.php' ) ) ); 1055 } 1056 1057 /** 1047 1058 * @ticket 35902 1048 1059 */ 1049 1060 public function test_is_attachment_should_not_match_numeric_id_to_post_title_beginning_with_id() { -
tests/phpunit/tests/template.php
diff --git tests/phpunit/tests/template.php tests/phpunit/tests/template.php index 00030f2..d303c57 100644
class Tests_Template extends WP_UnitTestCase { 36 36 'post_date' => '1984-02-25 12:34:56', 37 37 ) ); 38 38 set_post_format( self::$post, 'quote' ); 39 add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' ); 39 40 } 40 41 41 42 public function setUp() { … … class Tests_Template extends WP_UnitTestCase { 203 204 ) ); 204 205 } 205 206 207 /** 208 * @ticket 18375 209 */ 206 210 public function test_single_template_hierarchy_for_post() { 207 211 $this->assertTemplateHierarchy( get_permalink( self::$post ), array( 212 'templates/post.php', 208 213 'single-post-post-name-😀.php', 209 214 'single-post-post-name-%f0%9f%98%80.php', 210 215 'single-post.php', … … class Tests_Template extends WP_UnitTestCase { 228 233 ) ); 229 234 } 230 235 236 /** 237 * @ticket 18375 238 */ 239 public function test_single_template_hierarchy_for_custom_post_type_with_page_template() { 240 $cpt = self::factory()->post->create_and_get( array( 241 'post_type' => 'cpt', 242 'post_name' => 'cpt-name-😀', 243 ) ); 244 add_post_meta( $cpt->ID, '_wp_page_template', 'templates/cpt.php' ); 245 246 $this->assertTemplateHierarchy( get_permalink( $cpt ), array( 247 'templates/cpt.php', 248 'single-cpt-cpt-name-😀.php', 249 'single-cpt-cpt-name-%f0%9f%98%80.php', 250 'single-cpt.php', 251 'single.php', 252 'singular.php', 253 ) ); 254 } 255 231 256 public function test_attachment_template_hierarchy() { 232 257 $attachment = self::factory()->attachment->create_and_get( array( 233 258 'post_name' => 'attachment-name-😀',