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.



git-svn-id: https://develop.svn.wordpress.org/trunk@56296 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Isabel Brison
2023-07-25 06:28:28 +00:00
parent a176f19018
commit 1d7554d1b2
4 changed files with 90 additions and 18 deletions

View File

@@ -143,6 +143,50 @@ class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controlle
$this->assertTrue( $links['self'][0]['attributes']['embeddable'], 'Self link should be embeddable.' );
}
/**
* Tests that the correct filters are applied to the context parameter.
*
* By default, the REST response for the Posts Controller will not return all fields
* when the context is set to 'embed'. Assert that correct additional fields are added
* to the embedded Navigation Post, when the navigation fallback endpoint
* is called with the `_embed` param.
*
* @ticket 58557
*
* @covers wp_add_fields_to_navigation_fallback_embedded_links
*
* @since 6.3.0 Added Navigation Fallbacks endpoint.
*/
public function test_embedded_navigation_post_contains_required_fields() {
// First we'll use the navigation fallback to get a link to the navigation endpoint.
$request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' );
$response = rest_get_server()->dispatch( $request );
$links = $response->get_links();
// Extract the navigation endpoint URL from the response.
$embedded_navigation_href = $links['self'][0]['href'];
preg_match( '/\?rest_route=(.*)/', $embedded_navigation_href, $matches );
$navigation_endpoint = $matches[1];
// Fetch the "linked" navigation post from the endpoint, with the context parameter set to 'embed' to simulate fetching embedded links.
$request = new WP_REST_Request( 'GET', $navigation_endpoint );
$request->set_param( 'context', 'embed' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
// Verify that the additional status field is present.
$this->assertArrayHasKey( 'status', $data, 'Response title should contain a "status" field.' );
// Verify that the additional content fields are present.
$this->assertArrayHasKey( 'content', $data, 'Response should contain a "content" field.' );
$this->assertArrayHasKey( 'raw', $data['content'], 'Response content should contain a "raw" field.' );
$this->assertArrayHasKey( 'rendered', $data['content'], 'Response content should contain a "rendered" field.' );
$this->assertArrayHasKey( 'block_version', $data['content'], 'Response should contain a "block_version" field.' );
// Verify that the additional title.raw field is present.
$this->assertArrayHasKey( 'raw', $data['title'], 'Response title should contain a "raw" key.' );
}
private function get_navigations_in_database() {
$navs_in_db = new WP_Query(
array(