diff --git a/tests/src/python/test_qgsserver_wms_getfeatureinfo.py b/tests/src/python/test_qgsserver_wms_getfeatureinfo.py
index f403ffe3490..f9b20700911 100644
--- a/tests/src/python/test_qgsserver_wms_getfeatureinfo.py
+++ b/tests/src/python/test_qgsserver_wms_getfeatureinfo.py
@@ -719,6 +719,22 @@ class TestQgsServerWMSGetFeatureInfo(TestQgsServerWMSTestBase):
'test_project_wms_grouped_nested_layers.qgs',
normalizeJson=True)
+ @unittest.skipIf(os.environ.get('TRAVIS', '') == 'true', "This test cannot run in TRAVIS because it relies on cascading external services")
+ def testGetFeatureInfoCascadingLayers(self):
+ """Test that we can get feature info on cascading WMS layers"""
+
+ project_name = 'bug_gh31177_gfi_cascading_wms.qgs'
+ self.wms_request_compare('GetFeatureInfo',
+ '&BBOX=852729.31,5631138.51,853012.18,5631346.17' +
+ '&CRS=EPSG:3857' +
+ '&WIDTH=850&HEIGHT=624' +
+ '&QUERY_LAYERS=Alberate' +
+ '&INFO_FORMAT=application/vnd.ogc.gml' +
+ '&I=509&J=289' +
+ '&FEATURE_COUNT=10',
+ 'wms_getfeatureinfo_cascading_issue31177',
+ project_name)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/testdata/qgis_server/bug_gh31177_gfi_cascading_wms.qgs b/tests/testdata/qgis_server/bug_gh31177_gfi_cascading_wms.qgs
new file mode 100644
index 00000000000..3acaef488b0
--- /dev/null
+++ b/tests/testdata/qgis_server/bug_gh31177_gfi_cascading_wms.qgs
@@ -0,0 +1,288 @@
+
+
+
+
+
+
+
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+
+
+
+
+
+
+ - Alberate_66c1c9df_6c49_4094_b01d_4f9418bdce7c
+
+
+
+
+
+
+
+ meters
+
+ 852747.29199123778380454
+ 5631138.51772649865597486
+ 852994.20340507663786411
+ 5631346.17689236905425787
+
+ 0
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+ 0
+
+
+
+
+
+
+ meters
+
+ 852747.29199123778380454
+ 5631138.51772649865597486
+ 852994.20340507663786411
+ 5631346.17689236905425787
+
+ 0
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+ 0
+
+
+
+ meters
+
+ 852747.29199123778380454
+ 5631138.51772649865597486
+ 852994.20340507663786411
+ 5631346.17689236905425787
+
+ 0
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+ 0
+
+
+
+ meters
+
+ 852747.29199123778380454
+ 5631138.51772649865597486
+ 852994.20340507663786411
+ 5631346.17689236905425787
+
+ 0
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+ 0
+
+
+
+
+
+ 837573.41470312990713865
+ 5620073.25074507296085358
+ 867673.0918187202187255
+ 5645387.89191795606166124
+
+ Alberate_66c1c9df_6c49_4094_b01d_4f9418bdce7c
+ crs=EPSG:3857&dpiMode=7&format=image/png&layers=AlberatePt&styles&url=http://geomap.reteunitaria.piemonte.it/ws/siccms/coto-01/wmsg01/wms_sicc11_alberate
+
+
+
+ Alberate
+
+
+ +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
+ 3857
+ 3857
+ EPSG:3857
+ WGS 84 / Pseudo-Mercator
+ merc
+ WGS84
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+
+
+
+
+ false
+
+
+
+
+ wms
+
+
+
+
+
+
+
+ 1
+ 1
+ 1
+
+
+
+
+
+
+
+
+ None
+ WholeRaster
+ Estimated
+ 0.02
+ 0.98
+ 2
+
+
+
+
+
+
+ 0
+
+
+
+
+
+
+
+ 255
+ 255
+ 255
+ 255
+ 0
+ 255
+ 255
+
+
+
+ WGS84
+
+
+ m2
+ meters
+
+
+ 50
+ 16
+ 30
+ false
+ false
+ 0
+ false
+ false
+ true
+ 0
+ 255,0,0,255
+
+
+ false
+
+
+ true
+ 2
+
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Alessandro Pasotti
+ 2019-08-09T09:31:02
+
+
+
+
diff --git a/tests/testdata/qgis_server/wms_getfeatureinfo_cascading_issue31177.txt b/tests/testdata/qgis_server/wms_getfeatureinfo_cascading_issue31177.txt
new file mode 100644
index 00000000000..f4fe94abb4e
--- /dev/null
+++ b/tests/testdata/qgis_server/wms_getfeatureinfo_cascading_issue31177.txt
@@ -0,0 +1,22 @@
+Content-Length: 1268
+Content-Type: application/vnd.ogc.gml; charset=utf-8
+
+
+
+
+ 13498
+ 2
+ D'OVIDIO Enrico VIA
+ ACER PSEUDOPLATANUS LEOPOLDII
+ (non specificata)
+
+ 10
+ ALTRO
+ (non specificata)
+ PIANTA
+ 4175
+
+
+
+
+