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
28 changes: 28 additions & 0 deletions tests/phpunit/tests/rest-api/rest-pages-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,34 @@ public function test_homepage_action_links_do_not_exist_for_posts() {
$this->assertArrayNotHasKey( 'https://api.w.org/action-set-posts-page', $links, 'The action-set-posts-page link should not exist.' );
}

/**
* The pages of a collection have the links, compacted with the `wp` CURIE
* as the editors read them.
*
* @ticket 66327
*
* @covers WP_REST_Posts_Controller::get_available_actions
*/
public function test_homepage_action_links_exist_for_pages_in_a_collection() {
wp_set_current_user( self::$admin_id );

$page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
$request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
$request->set_query_params(
array(
'context' => 'edit',
'include' => array( $page_id ),
)
);

$response = rest_get_server()->dispatch( $request );
$data = rest_get_server()->response_to_data( $response, false );

$this->assertCount( 1, $data, 'The page should be listed.' );
$this->assertArrayHasKey( 'wp:action-set-homepage', $data[0]['_links'], 'The link should be compacted as `wp:action-set-homepage`.' );
$this->assertArrayHasKey( 'wp:action-set-posts-page', $data[0]['_links'], 'The link should be compacted as `wp:action-set-posts-page`.' );
}

/**
* Requests a post and returns the links of the response.
*
Expand Down
42 changes: 42 additions & 0 deletions tests/phpunit/tests/rest-api/rest-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5481,6 +5481,48 @@ public function test_trash_action_does_not_exist_for_trashed_post() {
$this->assertArrayNotHasKey( 'https://api.w.org/action-trash', $links );
}

/**
* @ticket 63670
*
* @covers WP_REST_Posts_Controller::get_available_actions
*/
public function test_trash_action_does_not_exist_in_view_context() {
wp_set_current_user( self::$editor_id );

$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id );
$request->set_query_params( array( 'context' => 'view' ) );

$response = rest_get_server()->dispatch( $request );
$links = $response->get_links();

$this->assertArrayNotHasKey( 'https://api.w.org/action-trash', $links );
}

/**
* @ticket 63670
*
* @covers WP_REST_Posts_Controller::get_available_actions
*/
public function test_trash_action_does_not_exist_when_user_cannot_delete() {
add_filter(
'map_meta_cap',
static function ( $caps, $cap ) {
return 'delete_post' === $cap ? array( 'do_not_allow' ) : $caps;
},
10,
2
);
wp_set_current_user( self::$editor_id );

$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id );
$request->set_query_params( array( 'context' => 'edit' ) );

$response = rest_get_server()->dispatch( $request );
$links = $response->get_links();

$this->assertArrayNotHasKey( 'https://api.w.org/action-trash', $links );
}


public function test_assign_author_action_exists_for_editor() {
wp_set_current_user( self::$editor_id );
Expand Down
21 changes: 21 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 @@ -467,4 +467,25 @@ public function test_get_item_schema_excludes_url_managed_view_properties() {
$this->assertArrayNotHasKey( 'page', $properties, "$label should not declare a `page` property." );
}
}

/**
* The table layout schema describes the column styles.
*
* @ticket 65981
*
* @covers ::get_item_schema
* @covers ::get_table_layout_schema
* @covers ::get_column_style_schema
*/
public function test_get_item_schema_describes_table_column_styles() {
$controller = new WP_REST_View_Config_Controller();
$schema = $controller->get_item_schema();

$styles = $schema['properties']['default_layouts']['properties']['table']['properties']['layout']['properties']['styles'];

$this->assertArrayHasKey( 'description', $styles, 'The column styles should be described.' );
foreach ( array( 'width', 'maxWidth', 'minWidth', 'align' ) as $property ) {
$this->assertArrayHasKey( 'description', $styles['additionalProperties']['properties'][ $property ], "The `$property` column style should be described." );
}
}
}
Loading