Make WordPress Core

Ticket #43439: 43439-unit-test-update.diff

File 43439-unit-test-update.diff, 2.9 KB (added by Mamaduka, 17 months ago)
  • tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php
    index efcbe9eb8d..d4762bb124 100644
    class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controlle 
    160160                // First we'll use the navigation fallback to get a link to the navigation endpoint.
    161161                $request  = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' );
    162162                $response = rest_get_server()->dispatch( $request );
    163                 $links    = $response->get_links();
    164 
    165                 // Extract the navigation endpoint URL from the response.
    166                 $embedded_navigation_href = $links['self'][0]['href'];
    167                 preg_match( '/\?rest_route=(.*)/', $embedded_navigation_href, $matches );
    168                 $navigation_endpoint = $matches[1];
    169 
    170                 // Fetch the "linked" navigation post from the endpoint, with the context parameter set to 'embed' to simulate fetching embedded links.
    171                 $request = new WP_REST_Request( 'GET', $navigation_endpoint );
    172                 $request->set_param( 'context', 'embed' );
    173                 $response = rest_get_server()->dispatch( $request );
    174                 $data     = $response->get_data();
     163                $data     = rest_get_server()->response_to_data( $response, true );
     164                $embedded = $data['_embedded']['self'][0];
    175165
    176166                // Verify that the additional status field is present.
    177                 $this->assertArrayHasKey( 'status', $data, 'Response title should contain a "status" field.' );
     167                $this->assertArrayHasKey( 'status', $embedded, 'Response title should contain a "status" field.' );
    178168
    179169                // Verify that the additional content fields are present.
    180                 $this->assertArrayHasKey( 'content', $data, 'Response should contain a "content" field.' );
    181                 $this->assertArrayHasKey( 'raw', $data['content'], 'Response content should contain a "raw" field.' );
    182                 $this->assertArrayHasKey( 'rendered', $data['content'], 'Response content should contain a "rendered" field.' );
    183                 $this->assertArrayHasKey( 'block_version', $data['content'], 'Response should contain a "block_version" field.' );
     170                $this->assertArrayHasKey( 'content', $embedded, 'Response should contain a "content" field.' );
     171                $this->assertArrayHasKey( 'raw', $embedded['content'], 'Response content should contain a "raw" field.' );
     172                $this->assertArrayHasKey( 'rendered', $embedded['content'], 'Response content should contain a "rendered" field.' );
     173                $this->assertArrayHasKey( 'block_version', $embedded['content'], 'Response should contain a "block_version" field.' );
    184174
    185175                // Verify that the additional title.raw field is present.
    186                 $this->assertArrayHasKey( 'raw', $data['title'], 'Response title should contain a "raw" key.' );
     176                $this->assertArrayHasKey( 'raw', $embedded['title'], 'Response title should contain a "raw" key.' );
    187177        }
    188178
    189179        private function get_navigations_in_database() {