Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @since 7.2.0
*
* @group restapi
* @group ms-required
*
* @coversDefaultClass WP_REST_Sites_Controller
*/
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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() {

Expand All @@ -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 );
Expand All @@ -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() {

Expand All @@ -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() {

Expand All @@ -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 );
Expand Down