user->create( array( 'role' => 'subscriber', ) ); self::$admin = $factory->user->create( array( 'role' => 'administrator', ) ); if ( is_multisite() ) { grant_super_admin( self::$admin ); } } /** * Clean up test fixtures. * * @since 5.6.0 */ public static function wpTearDownAfterClass() { self::delete_user( self::$subscriber ); self::delete_user( self::$admin ); } public function test_logged_out() { $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' ); $this->assertErrorResponse( 'rest_forbidden', $response, 401 ); } public function test_insufficient_caps() { wp_set_current_user( self::$subscriber ); $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' ); $this->assertErrorResponse( 'rest_forbidden', $response, 403 ); } /** * @group ms-excluded */ public function test_custom_capability() { wp_set_current_user( self::$admin ); add_filter( 'site_health_test_rest_capability_dotorg_communication', static function () { return 'a_custom_capability'; } ); $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' ); $this->assertErrorResponse( 'rest_forbidden', $response, 403 ); } public function test() { wp_set_current_user( self::$admin ); $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' ); $this->assertSame( 'dotorg_communication', $response->get_data()['test'] ); } }