Make WordPress Core

Changeset 64828


Ignore:
Timestamp:
10/27/2026 07:40:58 PM (4 days ago)
Author:
lancewillett
Message:

Tests: Cover template REST response preparation.

Replace the assertion-free template preparation test with checks for template properties and the self, collection, and about links.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14699

Props devmuhib, shailu25, huzaifaalmesbah.
See #40538.

File:
1 edited

Legend:

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

    r64390 r64828  
    945945
    946946        /**
    947          * @doesNotPerformAssertions
     947         * @ticket 40538
     948         *
     949         * @covers WP_REST_Templates_Controller::prepare_item_for_response
    948950         */
    949951        public function test_prepare_item() {
    950                 // Controller does not implement prepare_item().
     952                wp_set_current_user( self::$admin_id );
     953
     954                $endpoint = new WP_REST_Templates_Controller( 'wp_template' );
     955                $request  = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
     956                $request->set_param( 'context', 'edit' );
     957                $template = get_block_template( 'default//my_template', 'wp_template' );
     958                $response = $endpoint->prepare_item_for_response( $template, $request );
     959
     960                $this->assertInstanceOf( WP_REST_Response::class, $response );
     961                $this->assertSame( 200, $response->get_status() );
     962
     963                $data = $response->get_data();
     964                $this->assertSame( 'default//my_template', $data['id'] );
     965                $this->assertSame( 'default', $data['theme'] );
     966                $this->assertSame( 'my_template', $data['slug'] );
     967                $this->assertSame( 'wp_template', $data['type'] );
     968                $this->assertSame( 'custom', $data['source'] );
     969                $this->assertSame( 'Description of my template.', $data['description'] );
     970                $this->assertSame( 'My Template', $data['title']['raw'] );
     971                $this->assertSame( 'publish', $data['status'] );
     972                $this->assertSame( self::$template_post->ID, $data['wp_id'] );
     973
     974                $links = test_rest_expand_compact_links( $response->get_links() );
     975                $this->assertSame( rest_url( 'wp/v2/templates/default//my_template' ), $links['self'][0]['href'] );
     976                $this->assertSame( rest_url( 'wp/v2/templates' ), $links['collection'][0]['href'] );
     977                $this->assertSame( rest_url( 'wp/v2/types/wp_template' ), $links['about'][0]['href'] );
    951978        }
    952979
Note: See TracChangeset for help on using the changeset viewer.