Make WordPress Core


Ignore:
Timestamp:
02/02/2023 07:36:29 PM (2 years ago)
Author:
jorgefilipecosta
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-templates/getTemplateHierarchy.php

    r54269 r55194  
    88 */
    99class Tests_Block_Templates_GetTemplate_Hierarchy extends WP_Block_Templates_UnitTestCase {
     10
     11    public function set_up() {
     12        parent::set_up();
     13        register_post_type(
     14            'custom_book',
     15            array(
     16                'public'       => true,
     17                'show_in_rest' => true,
     18            )
     19        );
     20        register_taxonomy( 'book_type', 'custom_book' );
     21        register_taxonomy( 'books', 'custom_book' );
     22    }
     23
     24    public function tear_down() {
     25        unregister_post_type( 'custom_book' );
     26        unregister_taxonomy( 'book_type' );
     27        unregister_taxonomy( 'books' );
     28        parent::tear_down();
     29    }
    1030
    1131    /**
     
    84104                'expected' => array( 'category-fruits', 'category', 'archive', 'index' ),
    85105            ),
     106            'single word categories no prefix'         => array(
     107                'args'     => array( 'category-fruits', false ),
     108                'expected' => array( 'category-fruits', 'category', 'archive', 'index' ),
     109            ),
    86110            'multi word categories'                    => array(
    87111                'args'     => array( 'category-fruits-yellow', false, 'category' ),
    88112                'expected' => array( 'category-fruits-yellow', 'category', 'archive', 'index' ),
    89113            ),
     114            'multi word categories no prefix'          => array(
     115                'args'     => array( 'category-fruits-yellow', false ),
     116                'expected' => array( 'category-fruits-yellow', 'category', 'archive', 'index' ),
     117            ),
    90118            'single word taxonomy and term'            => array(
    91119                'args'     => array( 'taxonomy-books-action', false, 'taxonomy-books' ),
     120                'expected' => array( 'taxonomy-books-action', 'taxonomy-books', 'taxonomy', 'archive', 'index' ),
     121            ),
     122            'single word taxonomy and term no prefix'  => array(
     123                'args'     => array( 'taxonomy-books-action', false ),
    92124                'expected' => array( 'taxonomy-books-action', 'taxonomy-books', 'taxonomy', 'archive', 'index' ),
    93125            ),
     
    120152                'expected' => array( 'author-rigas', 'author', 'archive', 'index' ),
    121153            ),
     154            'multiple word taxonomy no prefix'         => array(
     155                'args'     => array( 'taxonomy-book_type-adventure', false ),
     156                'expected' => array( 'taxonomy-book_type-adventure', 'taxonomy-book_type', 'taxonomy', 'archive', 'index' ),
     157            ),
     158            'single post type no prefix'               => array(
     159                'args'     => array( 'single-custom_book', false ),
     160                'expected' => array(
     161                    'single-custom_book',
     162                    'single',
     163                    'singular',
     164                    'index',
     165                ),
     166            ),
     167            'single post and post type no prefix'      => array(
     168                'args'     => array( 'single-custom_book-book-1', false ),
     169                'expected' => array(
     170                    'single-custom_book-book-1',
     171                    'single-custom_book',
     172                    'single',
     173                    'singular',
     174                    'index',
     175                ),
     176            ),
     177            'page no prefix'                           => array(
     178                'args'     => array( 'page-hi', false ),
     179                'expected' => array(
     180                    'page-hi',
     181                    'page',
     182                    'singular',
     183                    'index',
     184                ),
     185            ),
     186            'post type archive no prefix'              => array(
     187                'args'     => array( 'archive-book', false ),
     188                'expected' => array(
     189                    'archive-book',
     190                    'archive',
     191                    'index',
     192                ),
     193            ),
    122194        );
    123195    }
Note: See TracChangeset for help on using the changeset viewer.