Skip to content

Commit

Permalink
[WMSServer] Add unit test for non queryable layer in getfeatureinfo o…
Browse files Browse the repository at this point in the history
…peration, add special case for group.
  • Loading branch information
tcoupin committed Jul 26, 2018
1 parent fd5c8e7 commit 0c18d3b
Show file tree
Hide file tree
Showing 6 changed files with 530 additions and 465 deletions.
21 changes: 12 additions & 9 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ namespace QgsWms
// remove unwanted layers (restricted layers, ...)
removeUnwantedLayers( layers, scaleDenominator );
// remove non identifiable layers
removeNonIdentifiableLayers( layers );
//removeNonIdentifiableLayers( layers );

Q_FOREACH ( QgsMapLayer *layer, layers )
{
Expand Down Expand Up @@ -1245,13 +1245,16 @@ namespace QgsWms
Q_FOREACH ( QString queryLayer, queryLayers )
{
bool validLayer = false;
bool queryableLayer = false;
bool queryableLayer = true;
Q_FOREACH ( QgsMapLayer *layer, layers )
{
if ( queryLayer == layerNickname( *layer ) )
{
validLayer = true;
queryableLayer = !mProject->nonIdentifiableLayers().contains( layer->id() );
queryableLayer = !mProject->nonIdentifiableLayers().contains( layer->id() ) ;
if (!queryableLayer){
break;
}

QDomElement layerElement;
if ( infoFormat == QgsWmsParameters::Format::GML )
Expand Down Expand Up @@ -1314,16 +1317,16 @@ namespace QgsWms
break;
}
}
if ( !queryableLayer )
{
QString msg = QObject::tr( "Layer '%1' is not queryable" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotQueryable" ), msg );
}
else if ( !validLayer && !mNicknameLayers.contains( queryLayer ) )
if ( !validLayer && !mNicknameLayers.contains( queryLayer ) && !mLayerGroups.contains( queryLayer ) )
{
QString msg = QObject::tr( "Layer '%1' not found" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotDefined" ), msg );
}
else if ( (validLayer && !queryableLayer) || (!validLayer && mLayerGroups.contains( queryLayer )) )
{
QString msg = QObject::tr( "Layer '%1' is not queryable" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotQueryable" ), msg );
}
}

if ( featuresRect )
Expand Down
27 changes: 27 additions & 0 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ def testGetFeatureInfo(self):
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
'wms_getfeatureinfo-text-xml')

# Test getfeatureinfo on non queryable layer
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer3&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer3&X=190&Y=320',
'wms_getfeatureinfo-testlayer3-notqueryable')

# Test getfeatureinfo on group without shortname (no queryable...)
self.wms_request_compare('GetFeatureInfo',
'&layers=groupwithoutshortname&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=groupwithoutshortname&X=190&Y=320',
'wms_getfeatureinfo-groupwithoutshortname-notqueryable')

# Test getfeatureinfo on group with shortname (no queryable...)
self.wms_request_compare('GetFeatureInfo',
'&layers=group_name&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=group_name&X=190&Y=320',
'wms_getfeatureinfo-group_name-notqueryable')

# Test getfeatureinfo response html
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
Expand Down
Loading

0 comments on commit 0c18d3b

Please sign in to comment.