Make WordPress Core


Ignore:
Timestamp:
03/11/2025 06:13:47 AM (8 months ago)
Author:
Mamaduka
Message:

REST API: Add additional default template data fields for the active theme.

The active theme(s) now return two additional properties, default_template_types and default_template_part_areas, in the REST response.

Props mamaduka, joemcgill, timothyblynjacobs, audrasjb, gigitux, peterwilsoncc, youknowriad, jorbin.
Fixes #62574.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r59822 r59965  
    164164     * @ticket 45016
    165165     * @ticket 61021
     166     * @ticket 62574.
    166167     */
    167168    public function test_get_items() {
     
    176177            'author',
    177178            'author_uri',
     179            'default_template_part_areas',
     180            'default_template_types',
    178181            'description',
    179182            'is_block_theme',
     
    355358     * @ticket 45016
    356359     * @ticket 61021
     360     * @ticket 62574
    357361     */
    358362    public function test_get_item_schema() {
     
    360364        $data       = $response->get_data();
    361365        $properties = $data['schema']['properties'];
    362         $this->assertCount( 18, $properties );
     366        $this->assertCount( 20, $properties );
    363367
    364368        $this->assertArrayHasKey( 'author', $properties );
     
    373377        $this->assertArrayHasKey( 'raw', $properties['description']['properties'] );
    374378        $this->assertArrayHasKey( 'rendered', $properties['description']['properties'] );
     379
     380        $this->assertArrayHasKey( 'default_template_part_areas', $properties );
     381        $this->assertArrayHasKey( 'default_template_types', $properties );
    375382
    376383        $this->assertArrayHasKey( 'is_block_theme', $properties );
     
    474481
    475482    /**
     483     * @ticket 62574
     484     */
     485    public function test_theme_default_template_part_areas() {
     486        $response = self::perform_active_theme_request();
     487        $result   = $response->get_data();
     488        $this->assertArrayHasKey( 'default_template_part_areas', $result[0] );
     489        $this->assertSame( get_allowed_block_template_part_areas(), $result[0]['default_template_part_areas'] );
     490    }
     491
     492    /**
     493     * @ticket 62574
     494     */
     495    public function test_theme_default_template_types() {
     496        $response = self::perform_active_theme_request();
     497        $result   = $response->get_data();
     498        $expected = array();
     499        foreach ( get_default_block_template_types() as $slug => $template_type ) {
     500            $template_type['slug'] = (string) $slug;
     501            $expected[]            = $template_type;
     502        }
     503
     504        $this->assertArrayHasKey( 'default_template_types', $result[0] );
     505        $this->assertSame( $expected, $result[0]['default_template_types'] );
     506    }
     507
     508    /**
    476509     * @ticket 49906
    477510     */
Note: See TracChangeset for help on using the changeset viewer.