@@ -106,6 +106,50 @@ public function test_get_items() {
106106 $ this ->assertCount ( 7 , $ sites );
107107 }
108108
109+ /**
110+ * Without an explicit network filter, only sites on the current network are returned.
111+ *
112+ * @ticket 40365
113+ * @covers ::get_items
114+ * @group ms-required
115+ */
116+ public function test_get_items_defaults_to_the_current_network () {
117+ wp_set_current_user ( self ::$ superadmin_id );
118+
119+ $ current_network_site = self ::factory ()->blog ->create ( array ( 'path ' => '/current/ ' ) );
120+
121+ $ other_network_id = self ::factory ()->network ->create (
122+ array (
123+ 'domain ' => 'other-network.example.org ' ,
124+ 'path ' => '/ ' ,
125+ )
126+ );
127+
128+ $ other_network_site = self ::factory ()->blog ->create (
129+ array (
130+ 'domain ' => 'other-network.example.org ' ,
131+ 'path ' => '/ ' ,
132+ 'network_id ' => $ other_network_id ,
133+ )
134+ );
135+
136+ $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/sites ' );
137+ $ response = rest_get_server ()->dispatch ( $ request );
138+
139+ $ this ->assertEquals ( 200 , $ response ->get_status () );
140+
141+ $ data = $ response ->get_data ();
142+ $ site_ids = wp_list_pluck ( $ data , 'id ' );
143+
144+ $ this ->assertContains ( $ current_network_site , $ site_ids , 'Sites on the current network should be returned. ' );
145+ $ this ->assertNotContains ( $ other_network_site , $ site_ids , 'Sites on another network should not be returned. ' );
146+
147+ $ current_network_id = get_current_network_id ();
148+ foreach ( $ data as $ site ) {
149+ $ this ->assertSame ( $ current_network_id , $ site ['network ' ], 'Every returned site should belong to the current network. ' );
150+ }
151+ }
152+
109153 /**
110154 * @ticket 40365
111155 * @covers ::get_item
0 commit comments