diff --git a/tests/src/core/testqgslayoutlabel.cpp b/tests/src/core/testqgslayoutlabel.cpp index c057e64608ec..6a398e14e0e2 100644 --- a/tests/src/core/testqgslayoutlabel.cpp +++ b/tests/src/core/testqgslayoutlabel.cpp @@ -50,6 +50,7 @@ class TestQgsLayoutLabel : public QObject void featureEvaluationUsingContext(); // test page expressions void pageEvaluation(); + void pageSizeEvaluation(); void marginMethods(); //tests getting/setting margins void render(); void renderAsHtml(); @@ -235,6 +236,34 @@ void TestQgsLayoutLabel::pageEvaluation() } } +void TestQgsLayoutLabel::pageSizeEvaluation() +{ + QgsLayout l( QgsProject::instance() ); + l.initializeDefaults(); + + QgsLayoutItemLabel *label = new QgsLayoutItemLabel( &l ); + label->setMargin( 1 ); + label->setText( QStringLiteral( "[%array_to_string(@layout_pageoffsets)%]" ) ); + l.addLayoutItem( label ); + + { + QString evaluated = label->currentText(); + QString expected = QStringLiteral( "0" ); + QCOMPARE( evaluated, expected ); + } + + // add a page and re-evaluate + QgsLayoutItemPage *page2 = new QgsLayoutItemPage( &l ); + page2->setPageSize( "A4", QgsLayoutItemPage::Landscape ); + l.pageCollection()->addPage( page2 ); + + { + QString evaluated = label->currentText(); + QString expected = QStringLiteral( "0,220" ); + QCOMPARE( evaluated, expected ); + } +} + void TestQgsLayoutLabel::marginMethods() { QgsLayout l( QgsProject::instance() );