Skip to content

Commit da93520

Browse files
committedMay 3, 2018
Setter and getter tests for relation reference widget
1 parent 19261f0 commit da93520

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
 

‎tests/src/gui/testqgsrelationreferencewidget.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class TestQgsRelationReferenceWidget : public QObject
4646
void testChainFilterRefreshed();
4747
void testChainFilterDeleteForeignKey();
4848
void testInvalidRelation();
49+
void testSetGetForeignKey();
4950

5051
private:
5152
std::unique_ptr<QgsVectorLayer> mLayer1;
@@ -129,14 +130,17 @@ void TestQgsRelationReferenceWidget::init()
129130

130131
void TestQgsRelationReferenceWidget::cleanup()
131132
{
133+
QgsProject::instance()->removeMapLayer( mLayer1.get() );
134+
QgsProject::instance()->removeMapLayer( mLayer2.get() );
132135
}
133136

134137
void TestQgsRelationReferenceWidget::testChainFilter()
135138
{
136139
// init a relation reference widget
137140
QStringList filterFields = { "material", "diameter", "raccord" };
138141

139-
QgsRelationReferenceWidget w( new QWidget() );
142+
QWidget parentWidget;
143+
QgsRelationReferenceWidget w( &parentWidget );
140144
w.setChainFilters( true );
141145
w.setFilterFields( filterFields );
142146
w.setRelation( *mRelation, true );
@@ -287,5 +291,22 @@ void TestQgsRelationReferenceWidget::testInvalidRelation()
287291
ww.initWidget( nullptr );
288292
}
289293

294+
void TestQgsRelationReferenceWidget::testSetGetForeignKey()
295+
{
296+
QWidget parentWidget;
297+
QgsRelationReferenceWidget w( &parentWidget );
298+
w.setRelation( *mRelation, true );
299+
w.init();
300+
301+
w.setForeignKey( 11 );
302+
QCOMPARE( w.foreignKey(), QVariant( 11 ) );
303+
304+
w.setForeignKey( 12 );
305+
QCOMPARE( w.foreignKey(), QVariant( 12 ) );
306+
307+
w.setForeignKey( QVariant( QVariant::Int ) );
308+
Q_ASSERT( w.foreignKey().isNull() );
309+
}
310+
290311
QGSTEST_MAIN( TestQgsRelationReferenceWidget )
291312
#include "testqgsrelationreferencewidget.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.