Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-view-config-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ public function replace( array $patch, int $version ) {
*
* ```php
* array(
* 'default_view' => array( 'search' => 'new search', 'fields' => array( 'newField' ) ),
* 'default_view' => array( 'titleField' => 'newTitleField', 'fields' => array( 'newField' ) ),
* 'default_layouts' => array( 'grid' => array( 'layout' => array( 'badgeFields' => array( 'newField' ) ) ) ),
* 'view_list' => array( array( 'slug' => 'table', 'title' => 'New title' ) ),
* )
* ```
*
* - default_view will be updated so the search string is 'new search' and the newField is appended to the list of fields.
* - default_view will be updated so the titleField is 'newTitleField' and the newField is appended to the list of fields.
* - default_layouts will be updated so that newField is appended to the badgeFields.
* - view_list will be updated so that the view with slug 'table' has its title changed to 'New title'.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,15 @@ public function get_item_schema() {
/**
* Returns the schema properties shared by all view types (ViewBase), excluding 'type'.
*
* Note that `search` and `page` are not part of the schema: they are managed
* via the URL, which is their only source of truth.
*
* @since 7.1.0
*
* @return array Schema properties for the base view configuration.
*/
protected function get_view_base_schema() {
return array(
'search' => array(
'type' => 'string',
),
'filters' => array(
'type' => 'array',
'items' => array(
Expand Down Expand Up @@ -444,9 +444,6 @@ protected function get_view_base_schema() {
),
),
),
'page' => array(
'type' => 'integer',
),
'perPage' => array(
'type' => 'integer',
),
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/rest-api/rest-view-config-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,29 @@ public function test_get_item_schema() {
array_keys( $schema['properties'] )
);
}

/**
* `search` and `page` are not part of the view schema: they are managed via
* the URL, which is their only source of truth.
*
* @covers ::get_item_schema
*/
public function test_get_item_schema_excludes_url_managed_view_properties() {
$controller = new WP_REST_View_Config_Controller();
$schema = $controller->get_item_schema();

$views = array(
'default_view' => $schema['properties']['default_view']['properties'],
'view_list item view' => $schema['properties']['view_list']['items']['properties']['view']['properties'],
'default_layouts.table' => $schema['properties']['default_layouts']['properties']['table']['properties'],
'default_layouts.grid' => $schema['properties']['default_layouts']['properties']['grid']['properties'],
'default_layouts.list' => $schema['properties']['default_layouts']['properties']['list']['properties'],
'default_layouts.activity' => $schema['properties']['default_layouts']['properties']['activity']['properties'],
);
Comment on lines +399 to +406

foreach ( $views as $label => $properties ) {
$this->assertArrayNotHasKey( 'search', $properties, "$label should not declare a `search` property." );
$this->assertArrayNotHasKey( 'page', $properties, "$label should not declare a `page` property." );
}
}
}
Loading