Editor: Remove need for template prefix in get_template_hierarchy.

This commit removes the need to pass a template prefix in get_template_hierarchy.
This is required because, in some block editor usages, the template prefix is not known.

Props youknowriad, davidbaumwald, jorgefilipecosta.
Fixes #57614.

git-svn-id: https://develop.svn.wordpress.org/trunk@55194 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jorge Costa
2023-02-02 19:36:29 +00:00
parent 99702c84eb
commit e53d61ac01
2 changed files with 102 additions and 7 deletions
@@ -8,6 +8,26 @@ require_once __DIR__ . '/base.php';
*/
class Tests_Block_Templates_GetTemplate_Hierarchy extends WP_Block_Templates_UnitTestCase {
public function set_up() {
parent::set_up();
register_post_type(
'custom_book',
array(
'public' => true,
'show_in_rest' => true,
)
);
register_taxonomy( 'book_type', 'custom_book' );
register_taxonomy( 'books', 'custom_book' );
}
public function tear_down() {
unregister_post_type( 'custom_book' );
unregister_taxonomy( 'book_type' );
unregister_taxonomy( 'books' );
parent::tear_down();
}
/**
* @dataProvider data_get_template_hierarchy
*
@@ -83,14 +103,26 @@ class Tests_Block_Templates_GetTemplate_Hierarchy extends WP_Block_Templates_Uni
'args' => array( 'category-fruits', false, 'category' ),
'expected' => array( 'category-fruits', 'category', 'archive', 'index' ),
),
'single word categories no prefix' => array(
'args' => array( 'category-fruits', false ),
'expected' => array( 'category-fruits', 'category', 'archive', 'index' ),
),
'multi word categories' => array(
'args' => array( 'category-fruits-yellow', false, 'category' ),
'expected' => array( 'category-fruits-yellow', 'category', 'archive', 'index' ),
),
'multi word categories no prefix' => array(
'args' => array( 'category-fruits-yellow', false ),
'expected' => array( 'category-fruits-yellow', 'category', 'archive', 'index' ),
),
'single word taxonomy and term' => array(
'args' => array( 'taxonomy-books-action', false, 'taxonomy-books' ),
'expected' => array( 'taxonomy-books-action', 'taxonomy-books', 'taxonomy', 'archive', 'index' ),
),
'single word taxonomy and term no prefix' => array(
'args' => array( 'taxonomy-books-action', false ),
'expected' => array( 'taxonomy-books-action', 'taxonomy-books', 'taxonomy', 'archive', 'index' ),
),
'single word taxonomy and multi word term' => array(
'args' => array( 'taxonomy-books-action-adventure', false, 'taxonomy-books' ),
'expected' => array( 'taxonomy-books-action-adventure', 'taxonomy-books', 'taxonomy', 'archive', 'index' ),
@@ -119,6 +151,46 @@ class Tests_Block_Templates_GetTemplate_Hierarchy extends WP_Block_Templates_Uni
'args' => array( 'author-rigas', false, 'author' ),
'expected' => array( 'author-rigas', 'author', 'archive', 'index' ),
),
'multiple word taxonomy no prefix' => array(
'args' => array( 'taxonomy-book_type-adventure', false ),
'expected' => array( 'taxonomy-book_type-adventure', 'taxonomy-book_type', 'taxonomy', 'archive', 'index' ),
),
'single post type no prefix' => array(
'args' => array( 'single-custom_book', false ),
'expected' => array(
'single-custom_book',
'single',
'singular',
'index',
),
),
'single post and post type no prefix' => array(
'args' => array( 'single-custom_book-book-1', false ),
'expected' => array(
'single-custom_book-book-1',
'single-custom_book',
'single',
'singular',
'index',
),
),
'page no prefix' => array(
'args' => array( 'page-hi', false ),
'expected' => array(
'page-hi',
'page',
'singular',
'index',
),
),
'post type archive no prefix' => array(
'args' => array( 'archive-book', false ),
'expected' => array(
'archive-book',
'archive',
'index',
),
),
);
}
}