Skip to content
Permalink
Browse files

Setter and getter tests for relation reference widget

  • Loading branch information
m-kuhn committed May 3, 2018
1 parent 19261f0 commit da93520c1fb14dbdaacdfbade05da1269e5e2296
Showing with 22 additions and 1 deletion.
  1. +22 −1 tests/src/gui/testqgsrelationreferencewidget.cpp
@@ -46,6 +46,7 @@ class TestQgsRelationReferenceWidget : public QObject
void testChainFilterRefreshed();
void testChainFilterDeleteForeignKey();
void testInvalidRelation();
void testSetGetForeignKey();

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

void TestQgsRelationReferenceWidget::cleanup()
{
QgsProject::instance()->removeMapLayer( mLayer1.get() );
QgsProject::instance()->removeMapLayer( mLayer2.get() );
}

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

QgsRelationReferenceWidget w( new QWidget() );
QWidget parentWidget;
QgsRelationReferenceWidget w( &parentWidget );
w.setChainFilters( true );
w.setFilterFields( filterFields );
w.setRelation( *mRelation, true );
@@ -287,5 +291,22 @@ void TestQgsRelationReferenceWidget::testInvalidRelation()
ww.initWidget( nullptr );
}

void TestQgsRelationReferenceWidget::testSetGetForeignKey()
{
QWidget parentWidget;
QgsRelationReferenceWidget w( &parentWidget );
w.setRelation( *mRelation, true );
w.init();

w.setForeignKey( 11 );
QCOMPARE( w.foreignKey(), QVariant( 11 ) );

w.setForeignKey( 12 );
QCOMPARE( w.foreignKey(), QVariant( 12 ) );

w.setForeignKey( QVariant( QVariant::Int ) );
Q_ASSERT( w.foreignKey().isNull() );
}

QGSTEST_MAIN( TestQgsRelationReferenceWidget )
#include "testqgsrelationreferencewidget.moc"

0 comments on commit da93520

Please sign in to comment.
You can’t perform that action at this time.