Skip to content

Commit

Permalink
Fix server WMS short name (unreported)
Browse files Browse the repository at this point in the history
This patch fixes a WMS server bug when "Short name" was
set in project settings for service capabilities.

When the short name was set, it was not possible
to load the whole WMS by selecting the root
layer named after the short name.

With tests for both cases (with and without short name).

Funded by Kanton Zug
  • Loading branch information
elpaso committed Jan 22, 2019
1 parent b129850 commit 4e8898d
Show file tree
Hide file tree
Showing 3 changed files with 1,993 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2548,8 +2548,9 @@ namespace QgsWms
}

// init groups
const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
initLayerGroupsRecursive( root, mProject->title() );
initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
}

void QgsRenderer::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
Expand Down
41 changes: 41 additions & 0 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Expand Up @@ -514,6 +514,47 @@ def test_wms_GetLegendGraphic_EmptyLegend(self):
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

def test_wms_GetLegendGraphic_wmsRootName(self):
"""Test an unreported issue when a wmsRootName short name is set in the service capabilities"""

# First test with the project title itself:
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_wms_grouped_layers.qgs',
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "QGIS%20Server%20-%20Grouped%20Layer",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"BBOX": "609152,5808188,625492,5814318",
"SRS": "EPSG:25832",
"SCALE": "38976"
}.items())])

h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

# Then test with the wmsRootName short name:
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_wms_grouped_layers_wmsroot.qgs',
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "All_grouped_layers",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"BBOX": "609152,5808188,625492,5814318",
"SRS": "EPSG:25832",
"SCALE": "38976"
}.items())])

h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))


if __name__ == '__main__':
unittest.main()

0 comments on commit 4e8898d

Please sign in to comment.