diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index 12badd6d9c5a0..f10b029e4b1cf 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -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. * diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index e78e5f764c3d4..0be413b4fb4a7 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -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 ); diff --git a/tests/phpunit/tests/rest-api/rest-view-config-controller.php b/tests/phpunit/tests/rest-api/rest-view-config-controller.php index 833f4e598a138..1cb6928e5ecc9 100644 --- a/tests/phpunit/tests/rest-api/rest-view-config-controller.php +++ b/tests/phpunit/tests/rest-api/rest-view-config-controller.php @@ -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." ); + } + } }