@@ -960,30 +960,46 @@ public function test_rest_preload_api_request_with_method() {
960960 }
961961
962962 /**
963+ * @dataProvider data_rest_preload_api_request_removes_trailing_slashes
964+ *
963965 * @ticket 51636
966+ * @ticket 57048
967+ *
968+ * @param string $preload_path The path to preload.
969+ * @param array|string $expected_preload_path Expected path after preloading.
964970 */
965- public function test_rest_preload_api_request_removes_trailing_slashes () {
971+ public function test_rest_preload_api_request_removes_trailing_slashes ( $ preload_path , $ expected_preload_path ) {
966972 $ rest_server = $ GLOBALS ['wp_rest_server ' ];
967973 $ GLOBALS ['wp_rest_server ' ] = null ;
968974
969- $ preload_paths = array (
970- '/wp/v2/types// ' ,
971- array ( '/wp/v2/media/// ' , 'OPTIONS ' ),
972- '//// ' ,
973- );
974-
975- $ preload_data = array_reduce (
976- $ preload_paths ,
977- 'rest_preload_api_request ' ,
978- array ()
979- );
980-
981- $ this ->assertSame ( array_keys ( $ preload_data ), array ( '/wp/v2/types ' , 'OPTIONS ' , '/ ' ) );
982- $ this ->assertArrayHasKey ( '/wp/v2/media ' , $ preload_data ['OPTIONS ' ] );
975+ $ actual_preload_path = rest_preload_api_request ( array (), $ preload_path );
976+ if ( '' !== $ preload_path ) {
977+ $ actual_preload_path = key ( $ actual_preload_path );
978+ }
979+ $ this ->assertSame ( $ expected_preload_path , $ actual_preload_path );
983980
984981 $ GLOBALS ['wp_rest_server ' ] = $ rest_server ;
985982 }
986983
984+ /**
985+ * Data provider.
986+ *
987+ * @return array
988+ */
989+ public static function data_rest_preload_api_request_removes_trailing_slashes () {
990+ return array (
991+ 'no query part ' => array ( '/wp/v2/types// ' , '/wp/v2/types ' ),
992+ 'no query part, more slashes ' => array ( '/wp/v2/media/// ' , '/wp/v2/media ' ),
993+ 'only slashes ' => array ( '//// ' , '/ ' ),
994+ 'empty path ' => array ( '' , array () ),
995+ 'no query parameters ' => array ( '/wp/v2/types//?//// ' , '/wp/v2/types? ' ),
996+ 'no query parameters, with slashes ' => array ( '/wp/v2/types//?fields//// ' , '/wp/v2/types?fields ' ),
997+ 'query parameters with no values ' => array ( '/wp/v2/types//?fields=//// ' , '/wp/v2/types?fields= ' ),
998+ 'single query parameter ' => array ( '/wp/v2/types//?_fields=foo,bar//// ' , '/wp/v2/types?_fields=foo,bar ' ),
999+ 'multiple query parameters ' => array ( '/wp/v2/types////?_fields=foo,bar&limit=1000//// ' , '/wp/v2/types?_fields=foo,bar&limit=1000 ' ),
1000+ );
1001+ }
1002+
9871003 /**
9881004 * @ticket 40614
9891005 */
0 commit comments