Make WordPress Core

Changeset 64831


Ignore:
Timestamp:
10/27/2026 07:45:02 PM (40 hours ago)
Author:
lancewillett
Message:

Tests: Cover block directory REST response links.

Check that block directory response preparation includes an install-plugin link by default and omits links when _fields excludes them.

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

Props devmuhib.
See #40538.

File:
1 edited

Legend:

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

    r64075 r64831  
    220220
    221221                $this->assertSame( $expected, $response->get_data() );
     222
     223                $links = test_rest_expand_compact_links( $response->get_links() );
     224                $this->assertArrayHasKey( 'https://api.w.org/install-plugin', $links );
     225        }
     226
     227        /**
     228         * @ticket 40538
     229         */
     230        public function test_prepare_item_limit_fields() {
     231                wp_set_current_user( self::$admin_id );
     232
     233                $controller = new WP_REST_Block_Directory_Controller();
     234
     235                $plugin  = $this->get_mock_plugin();
     236                $request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' );
     237                $request->set_query_params(
     238                        array(
     239                                'term'    => 'block',
     240                                '_fields' => 'id,name',
     241                        )
     242                );
     243
     244                $response = $controller->prepare_item_for_response( $plugin, $request );
     245
     246                $this->assertEmpty( $response->get_links(), 'Links should be omitted when not requested in _fields.' );
    222247        }
    223248
Note: See TracChangeset for help on using the changeset viewer.