@@ -432,27 +432,31 @@ void TestQgsExpressionContext::evaluate()
432432void TestQgsExpressionContext::setFeature ()
433433{
434434 QgsFeature feature ( 50LL );
435+ feature.setValid ( true );
435436 QgsExpressionContextScope scope;
436437 scope.setFeature ( feature );
437- QVERIFY ( scope.hasVariable ( QgsExpressionContext::EXPR_FEATURE ) );
438- QCOMPARE (( qvariant_cast<QgsFeature>( scope.variable ( QgsExpressionContext::EXPR_FEATURE ) ) ).id (), 50LL );
438+ QVERIFY ( scope.hasFeature () );
439+ QCOMPARE ( scope.feature ().id (), 50LL );
440+ scope.removeFeature ();
441+ QVERIFY ( !scope.hasFeature () );
442+ QVERIFY ( !scope.feature ().isValid () );
439443
440444 // test setting a feature in a context with no scopes
441445 QgsExpressionContext emptyContext;
442446 QVERIFY ( !emptyContext.feature ().isValid () );
443447 emptyContext.setFeature ( feature );
444448 // setFeature should have created a scope
445449 QCOMPARE ( emptyContext.scopeCount (), 1 );
446- QVERIFY ( emptyContext.hasVariable ( QgsExpressionContext:: EXPR_FEATURE ) );
447- QCOMPARE (( qvariant_cast<QgsFeature>( emptyContext.variable ( QgsExpressionContext:: EXPR_FEATURE ) ) ).id (), 50LL );
450+ QVERIFY ( emptyContext.feature (). isValid ( ) );
451+ QCOMPARE ( emptyContext.feature ( ).id (), 50LL );
448452 QCOMPARE ( emptyContext.feature ().id (), 50LL );
449453
450454 QgsExpressionContext contextWithScope;
451455 contextWithScope << new QgsExpressionContextScope ();
452456 contextWithScope.setFeature ( feature );
453457 QCOMPARE ( contextWithScope.scopeCount (), 1 );
454- QVERIFY ( contextWithScope.hasVariable ( QgsExpressionContext:: EXPR_FEATURE ) );
455- QCOMPARE (( qvariant_cast<QgsFeature>( contextWithScope.variable ( QgsExpressionContext:: EXPR_FEATURE ) ) ).id (), 50LL );
458+ QVERIFY ( contextWithScope.feature (). isValid ( ) );
459+ QCOMPARE ( contextWithScope.feature ( ).id (), 50LL );
456460 QCOMPARE ( contextWithScope.feature ().id (), 50LL );
457461}
458462
@@ -652,7 +656,7 @@ void TestQgsExpressionContext::featureBasedContext()
652656
653657 QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext ( f, fields );
654658
655- QgsFeature evalFeature = qvariant_cast<QgsFeature>( context.variable ( QStringLiteral ( " _feature_ " ) ) );
659+ QgsFeature evalFeature = context.feature ( );
656660 QgsFields evalFields = qvariant_cast<QgsFields>( context.variable ( QStringLiteral ( " _fields_" ) ) );
657661 QCOMPARE ( evalFeature.attributes (), f.attributes () );
658662 QCOMPARE ( evalFields, fields );
0 commit comments