Skip to content

Commit

Permalink
[Test] Add a expressionFromOgcFilter test with And, Or and PropertyIs…
Browse files Browse the repository at this point in the history
…Like with wildCard to PyQgsOgcUtils
  • Loading branch information
rldhont committed Jul 8, 2019
1 parent da9a505 commit d161379
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/src/python/test_qgsogcutils.py
Expand Up @@ -394,6 +394,49 @@ def test_expressionFromOgcFilterWithString(self):
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > \'15e-01\' AND id < \'35e-01\'')

def test_expressionFromOgcFilterWithAndOrPropertyIsLike(self):
"""
Test expressionFromOgcFilter with And, Or and PropertyIsLike with wildCard
"""

vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.LongLong), QgsField('THEME', QVariant.String), QgsField('PROGRAMME', QVariant.String)])
vl.updateFields()

f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsLike escape="\\" wildCard="%" singleChar="_">
<ogc:PropertyName>THEME</ogc:PropertyName>
<ogc:Literal>%Phytoplancton total%</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:Or>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>REPHY;*</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>*;REPHY</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>*;REPHY;*</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>^REPHY$</ogc:Literal>
</ogc:PropertyIsLike>
</ogc:Or>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)

e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'THEME LIKE \'%Phytoplancton total%\' AND (PROGRAMME ILIKE \'REPHY;%\' OR PROGRAMME ILIKE \'%;REPHY\' OR PROGRAMME ILIKE \'%;REPHY;%\' OR PROGRAMME ILIKE \'^REPHY$\')')


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

0 comments on commit d161379

Please sign in to comment.