Make WordPress Core


Ignore:
Timestamp:
07/25/2023 06:28:28 AM (3 years ago)
Author:
isabel_brison
Message:

Editor: load title on navigation fallback.

Adds raw title property when loading the navigation fallback with an embed context.

Props ramonopoly, get_dave, scruffian, mukesh27, audrasjb.
Fixes #58557.

File:
1 edited

Legend:

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

    r56052 r56296  
    142142
    143143        $this->assertTrue( $links['self'][0]['attributes']['embeddable'], 'Self link should be embeddable.' );
     144    }
     145
     146    /**
     147     * Tests that the correct filters are applied to the context parameter.
     148     *
     149     * By default, the REST response for the Posts Controller will not return all fields
     150     * when the context is set to 'embed'. Assert that correct additional fields are added
     151     * to the embedded Navigation Post, when the navigation fallback endpoint
     152     * is called with the `_embed` param.
     153     *
     154     * @ticket 58557
     155     *
     156     * @covers wp_add_fields_to_navigation_fallback_embedded_links
     157     *
     158     * @since 6.3.0 Added Navigation Fallbacks endpoint.
     159     */
     160    public function test_embedded_navigation_post_contains_required_fields() {
     161        // First we'll use the navigation fallback to get a link to the navigation endpoint.
     162        $request  = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' );
     163        $response = rest_get_server()->dispatch( $request );
     164        $links    = $response->get_links();
     165
     166        // Extract the navigation endpoint URL from the response.
     167        $embedded_navigation_href = $links['self'][0]['href'];
     168        preg_match( '/\?rest_route=(.*)/', $embedded_navigation_href, $matches );
     169        $navigation_endpoint = $matches[1];
     170
     171        // Fetch the "linked" navigation post from the endpoint, with the context parameter set to 'embed' to simulate fetching embedded links.
     172        $request = new WP_REST_Request( 'GET', $navigation_endpoint );
     173        $request->set_param( 'context', 'embed' );
     174        $response = rest_get_server()->dispatch( $request );
     175        $data     = $response->get_data();
     176
     177        // Verify that the additional status field is present.
     178        $this->assertArrayHasKey( 'status', $data, 'Response title should contain a "status" field.' );
     179
     180        // Verify that the additional content fields are present.
     181        $this->assertArrayHasKey( 'content', $data, 'Response should contain a "content" field.' );
     182        $this->assertArrayHasKey( 'raw', $data['content'], 'Response content should contain a "raw" field.' );
     183        $this->assertArrayHasKey( 'rendered', $data['content'], 'Response content should contain a "rendered" field.' );
     184        $this->assertArrayHasKey( 'block_version', $data['content'], 'Response should contain a "block_version" field.' );
     185
     186        // Verify that the additional title.raw field is present.
     187        $this->assertArrayHasKey( 'raw', $data['title'], 'Response title should contain a "raw" key.' );
    144188    }
    145189
Note: See TracChangeset for help on using the changeset viewer.