diff --git a/src/server/services/wms/qgswmsgetcapabilities.cpp b/src/server/services/wms/qgswmsgetcapabilities.cpp
index f6b9ca268e65..6437de375170 100644
--- a/src/server/services/wms/qgswmsgetcapabilities.cpp
+++ b/src/server/services/wms/qgswmsgetcapabilities.cpp
@@ -1017,6 +1017,12 @@ namespace QgsWms
}
handleLayersFromTreeGroup( doc, layerElem, serverIface, project, request, treeGroupChild, wmsLayerInfos, projectSettings );
+
+ // Check if child layer elements have been added
+ if ( layerElem.elementsByTagName( QStringLiteral( "Layer" ) ).length() == 0 )
+ {
+ continue;
+ }
}
else
{
diff --git a/tests/src/python/test_qgsserver_accesscontrol_wms.py b/tests/src/python/test_qgsserver_accesscontrol_wms.py
index d1c939fa3ca8..cb03d9bc977a 100644
--- a/tests/src/python/test_qgsserver_accesscontrol_wms.py
+++ b/tests/src/python/test_qgsserver_accesscontrol_wms.py
@@ -44,6 +44,9 @@ def test_wms_getcapabilities(self):
self.assertTrue(
str(response).find("Hello") != -1,
f"No Hello layer in GetCapabilities\n{response}")
+ self.assertTrue(
+ str(response).find("Country_grp") != -1,
+ f"Unexpected Country_grp layer in GetCapabilities\n{response}")
self.assertTrue(
str(response).find("Country") != -1,
f"No Country layer in GetCapabilities\n{response}")
@@ -52,12 +55,13 @@ def test_wms_getcapabilities(self):
self.assertTrue(
str(response).find("Hello") != -1,
f"No Hello layer in GetCapabilities\n{response}")
+ self.assertFalse(
+ str(response).find("Country_grp") != -1,
+ f"Unexpected Country_grp layer in GetCapabilities\n{response}")
self.assertFalse(
str(response).find("Country") != -1,
f"Unexpected Country layer in GetCapabilities\n{response}")
- # This test hasn't run yet
- @unittest.expectedFailure
def test_wms_getprojectsettings(self):
query_string = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
@@ -78,7 +82,7 @@ def test_wms_getprojectsettings(self):
f"No Country_grp layer in GetProjectSettings\n{response}")
self.assertTrue(
str(response).find(
- "Country_Diagrams,Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point") != -1,
+ "Country_Diagrams,Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello_Filter,Hello_OnOff,Hello,db_point") != -1,
f"LayerDrawingOrder in GetProjectSettings\n{response}")
response, headers = self._get_restricted(query_string)
@@ -93,7 +97,7 @@ def test_wms_getprojectsettings(self):
f"Unexpected Country_grp layer in GetProjectSettings\n{response}")
self.assertTrue(
str(response).find(
- "Country_Diagrams,Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point") != -1,
+ "Country_Diagrams,Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello_Filter,Hello,db_point") != -1,
f"Wrong LayerDrawingOrder in GetProjectSettings\n{response}")
def test_wms_getcontext(self):