|
13 | 13 | __revision__ = '$Format:%H$' |
14 | 14 |
|
15 | 15 | import qgis # NOQA |
| 16 | +import os |
| 17 | +import filecmp |
16 | 18 |
|
17 | 19 | from qgis.core import (QgsVectorLayer, |
18 | | - QgsReadWriteContext) |
| 20 | + QgsReadWriteContext, |
| 21 | + QgsEditFormConfig) |
19 | 22 | from qgis.gui import QgsGui |
20 | 23 |
|
21 | 24 | from qgis.testing import start_app, unittest |
22 | 25 | from qgis.PyQt.QtXml import QDomDocument, QDomElement |
| 26 | +from utilities import unitTestDataPath |
23 | 27 |
|
| 28 | +TEST_DATA_DIR = unitTestDataPath() |
24 | 29 | start_app() |
25 | 30 |
|
26 | 31 |
|
@@ -57,6 +62,33 @@ def testReadWriteXml(self): |
57 | 62 | self.assertFalse(config2.labelOnTop(0)) |
58 | 63 | self.assertTrue(config2.labelOnTop(1)) |
59 | 64 |
|
| 65 | + def testFormUi(self): |
| 66 | + layer = self.createLayer() |
| 67 | + config = layer.editFormConfig() |
| 68 | + |
| 69 | + uiLocal = os.path.join(TEST_DATA_DIR, 'layer_attribute_form.ui') |
| 70 | + (ok, _) = config.setUiForm(uiLocal) |
| 71 | + self.assertTrue(ok) |
| 72 | + self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout) |
| 73 | + self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiLocal) |
| 74 | + self.assertEqual(config.uiForm(QgsEditFormConfig.LocalCopy), uiLocal) |
| 75 | + |
| 76 | + uiUrl = 'https://raw.githubusercontent.com/3nids/QGIS/7ac09b1f9b1921e7f95ab077d97dcf0dfd57be4a/tests/testdata/layer_attribute_form.ui' |
| 77 | + (ok, _) = config.setUiForm(uiUrl) |
| 78 | + self.assertTrue(ok) |
| 79 | + self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout) |
| 80 | + self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiUrl) |
| 81 | + localCopy = config.uiForm(QgsEditFormConfig.LocalCopy) |
| 82 | + self.assertNotEqual(localCopy, uiUrl) |
| 83 | + filecmp.cmp(localCopy, uiLocal) |
| 84 | + |
| 85 | + uiBadUrl = 'http://www.qwertzuiopasdfghjklyxcvbnm.qwer/xxx.ui' |
| 86 | + (ok, _) = config.setUiForm(uiBadUrl) |
| 87 | + self.assertFalse(ok) |
| 88 | + self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout) |
| 89 | + self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiBadUrl) |
| 90 | + self.assertEqual(config.uiForm(QgsEditFormConfig.LocalCopy), '') |
| 91 | + |
60 | 92 | def testReadOnly(self): |
61 | 93 | layer = self.createLayer() |
62 | 94 | config = layer.editFormConfig() |
|
0 commit comments