From b7a51db08ea845dde94b1748376e5ad823025b31 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 28 Aug 2026 15:51:55 +0100 Subject: [PATCH] Tests: Rename rest-sites-controller.php to wpRestSitesController.php and add missing group annotations --- ...ntroller.php => wpRestSitesController.php} | 112 +++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) rename tests/phpunit/tests/rest-api/{rest-sites-controller.php => wpRestSitesController.php} (91%) diff --git a/tests/phpunit/tests/rest-api/rest-sites-controller.php b/tests/phpunit/tests/rest-api/wpRestSitesController.php similarity index 91% rename from tests/phpunit/tests/rest-api/rest-sites-controller.php rename to tests/phpunit/tests/rest-api/wpRestSitesController.php index e16d7310ea0d9..789eb40852f2c 100644 --- a/tests/phpunit/tests/rest-api/rest-sites-controller.php +++ b/tests/phpunit/tests/rest-api/wpRestSitesController.php @@ -8,7 +8,6 @@ * @since 7.2.0 * * @group restapi - * @group ms-required * * @coversDefaultClass WP_REST_Sites_Controller */ @@ -56,6 +55,7 @@ public function test_register_routes() { /** * @ticket 40365 * @covers ::get_context_param + * @group ms-required */ public function test_context_param() { wp_set_current_user( self::$superadmin_id ); @@ -77,6 +77,7 @@ public function test_context_param() { /** * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items() { wp_set_current_user( self::$superadmin_id ); @@ -91,6 +92,7 @@ public function test_get_items() { /** * @ticket 40365 * @covers ::get_item + * @group ms-required */ public function test_get_item() { wp_set_current_user( self::$superadmin_id ); @@ -112,11 +114,38 @@ public function test_get_item() { $this->assertEquals( 1, $data['public'] ); } + /** + * @ticket 40365 + * @covers ::get_items + * @group ms-excluded + */ + public function test_get_items_no_ms() { + wp_set_current_user( self::$superadmin_id ); + $request = new WP_REST_Request( 'GET', '/wp/v2/sites' ); + $response = rest_get_server()->dispatch( $request ); + $this->assertErrorResponse( 'rest_multisite_not_installed', $response, 400 ); + } + + /** + * @ticket 40365 + * @covers ::get_item + * @group ms-excluded + */ + public function test_get_item_no_ms() { + wp_set_current_user( self::$superadmin_id ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/sites/1' ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertErrorResponse( 'rest_multisite_not_installed', $response, 400 ); + } + /** * An unknown ID is a 404, not an empty site. * * @ticket 40365 * @covers ::get_item + * @group ms-required */ public function test_get_item_invalid_id() { wp_set_current_user( self::$superadmin_id ); @@ -130,6 +159,7 @@ public function test_get_item_invalid_id() { /** * @ticket 40365 * @covers ::create_item + * @group ms-required */ public function test_create_item() { wp_set_current_user( self::$superadmin_id ); @@ -156,6 +186,7 @@ public function test_create_item() { /** * @ticket 40365 * @covers ::update_item + * @group ms-required */ public function test_update_item() { wp_set_current_user( self::$superadmin_id ); @@ -177,9 +208,44 @@ public function test_update_item() { $this->assertEquals( '/incididunt/', get_site( $blog_id )->path ); } + /** + * @ticket 40365 + * @covers ::create_item + * @group ms-excluded + */ + public function test_create_item_no_ms() { + wp_set_current_user( self::$superadmin_id ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/sites' ); + $request->set_param( 'domain', WP_TESTS_DOMAIN ); + $request->set_param( 'path', '/tempor/' ); + + $response = rest_get_server()->dispatch( $request ); + + $this->assertErrorResponse( 'rest_multisite_not_installed', $response, 400 ); + } + + /** + * @ticket 40365 + * @covers ::update_item + * @group ms-excluded + */ + public function test_update_item_no_ms() { + wp_set_current_user( self::$superadmin_id ); + + $request = new WP_REST_Request( 'PUT', '/wp/v2/sites/1' ); + $request->set_param( 'path', '/incididunt/' ); + $request->set_param( 'mature', 1 ); + + $response = rest_get_server()->dispatch( $request ); + + $this->assertErrorResponse( 'rest_multisite_not_installed', $response, 400 ); + } + /** * @ticket 40365 * @covers ::delete_item + * @group ms-required */ public function test_delete_item() { wp_set_current_user( self::$superadmin_id ); @@ -200,11 +266,28 @@ public function test_delete_item() { $this->assertNull( get_site( $blog_id ) ); } + /** + * @ticket 40365 + * @covers ::delete_item + * @group ms-excluded + */ + public function test_delete_item_no_ms() { + wp_set_current_user( self::$superadmin_id ); + + $request = new WP_REST_Request( 'DELETE', '/wp/v2/sites/1' ); + $request->set_param( 'force', true ); + + $response = rest_get_server()->dispatch( $request ); + + $this->assertErrorResponse( 'rest_multisite_not_installed', $response, 400 ); + } + /** * Deleting a site drops its tables. * * @ticket 40365 * @covers ::delete_item + * @group ms-required */ public function test_delete_item_uninitializes_the_site() { wp_set_current_user( self::$superadmin_id ); @@ -227,6 +310,7 @@ public function test_delete_item_uninitializes_the_site() { * * @ticket 40365 * @covers ::delete_item + * @group ms-required */ public function test_delete_item_requires_force() { wp_set_current_user( self::$superadmin_id ); @@ -245,6 +329,7 @@ public function test_delete_item_requires_force() { * * @ticket 40365 * @covers ::delete_item + * @group ms-required */ public function test_delete_main_site_is_not_allowed() { wp_set_current_user( self::$superadmin_id ); @@ -263,6 +348,7 @@ public function test_delete_main_site_is_not_allowed() { /** * @ticket 40365 * @covers ::prepare_item_for_response + * @group ms-required */ public function test_prepare_item() { wp_set_current_user( self::$superadmin_id ); @@ -343,6 +429,7 @@ public function test_get_item_schema() { * * @ticket 40365 * @covers ::prepare_item_for_response + * @group ms-required */ public function test_get_item_uses_the_schema_types() { wp_set_current_user( self::$superadmin_id ); @@ -368,6 +455,7 @@ public function test_get_item_uses_the_schema_types() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_by_status() { wp_set_current_user( self::$superadmin_id ); @@ -400,6 +488,7 @@ public function test_get_items_filter_by_status() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_without_status_filter_returns_every_site() { wp_set_current_user( self::$superadmin_id ); @@ -419,6 +508,7 @@ public function test_get_items_without_status_filter_returns_every_site() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_by_lang_id() { wp_set_current_user( self::$superadmin_id ); @@ -449,6 +539,7 @@ public function test_get_items_filter_by_lang_id() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_by_registration_date() { wp_set_current_user( self::$superadmin_id ); @@ -479,6 +570,7 @@ public function test_get_items_filter_by_registration_date() { * * @ticket 40365 * @covers ::create_item + * @group ms-required */ public function test_create_item_sets_the_title_and_the_administrator() { wp_set_current_user( self::$superadmin_id ); @@ -512,6 +604,7 @@ public function test_create_item_sets_the_title_and_the_administrator() { * * @ticket 40365 * @covers ::create_item + * @group ms-required */ public function test_create_item_rejects_an_unknown_user_id() { wp_set_current_user( self::$superadmin_id ); @@ -558,6 +651,7 @@ public function test_update_item_does_not_accept_the_creation_fields() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_me_filter_reports_the_filtered_total() { $blog_ids = self::factory()->blog->create_many( 3 ); @@ -590,6 +684,7 @@ public function test_get_items_me_filter_reports_the_filtered_total() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_user_without_sites() { wp_set_current_user( self::$superadmin_id ); @@ -612,6 +707,7 @@ public function test_get_items_filter_user_without_sites() { * * @ticket 40365 * @covers ::prepare_links + * @group ms-required */ public function test_get_item_has_links() { wp_set_current_user( self::$superadmin_id ); @@ -634,6 +730,7 @@ public function test_get_item_has_links() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_does_not_switch_blogs_for_table_columns() { wp_set_current_user( self::$superadmin_id ); @@ -671,6 +768,7 @@ public function test_get_items_does_not_switch_blogs_for_table_columns() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_head_request_returns_no_body() { wp_set_current_user( self::$superadmin_id ); @@ -692,6 +790,7 @@ public function test_head_request_returns_no_body() { * * @ticket 40365 * @covers ::get_item + * @group ms-required */ public function test_head_request_on_a_single_site_returns_no_body() { wp_set_current_user( self::$superadmin_id ); @@ -721,6 +820,7 @@ public function test_head_request_on_a_single_site_returns_no_body() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_are_ordered_ascending() { wp_set_current_user( self::$superadmin_id ); @@ -740,6 +840,7 @@ public function test_get_items_are_ordered_ascending() { * * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_orderby_id_list_without_a_list() { wp_set_current_user( self::$superadmin_id ); @@ -760,6 +861,7 @@ public function test_get_items_orderby_id_list_without_a_list() { * * @ticket 40365 * @covers ::update_item + * @group ms-required */ public function test_update_item_does_not_slash_the_stored_data() { wp_set_current_user( self::$superadmin_id ); @@ -780,6 +882,7 @@ public function test_update_item_does_not_slash_the_stored_data() { * * @ticket 40365 * @covers ::create_item + * @group ms-required */ public function test_create_item_stores_the_status_fields() { wp_set_current_user( self::$superadmin_id ); @@ -808,6 +911,7 @@ public function test_create_item_stores_the_status_fields() { * * @ticket 40365 * @covers ::update_item + * @group ms-required */ public function test_update_item_keeps_fields_that_were_not_sent() { wp_set_current_user( self::$superadmin_id ); @@ -833,6 +937,7 @@ public function test_update_item_keeps_fields_that_were_not_sent() { * * @ticket 40365 * @covers ::update_item + * @group ms-required */ public function test_update_item_keeps_the_domain() { wp_set_current_user( self::$superadmin_id ); @@ -908,6 +1013,7 @@ public function test_invalid_user_input() { /** * @ticket 40365 * @covers ::get_user_site_ids + * @group ms-required */ public function test_valid_user_input() { @@ -924,6 +1030,7 @@ public function test_valid_user_input() { /** * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_user() { wp_set_current_user( self::$superadmin_id ); @@ -946,6 +1053,7 @@ public function test_get_items_filter_user() { /** * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_me_filter_user() { @@ -968,6 +1076,7 @@ public function test_get_items_me_filter_user() { /** * @ticket 40365 * @covers ::get_items_permissions_check + * @group ms-required */ public function test_get_items_filter_user_no_access() { @@ -989,6 +1098,7 @@ public function test_get_items_filter_user_no_access() { /** * @ticket 40365 * @covers ::get_items + * @group ms-required */ public function test_get_items_filter_with_includes_user() { wp_set_current_user( self::$superadmin_id );