Skip to content
Permalink
Browse files

Add unit tests for save user name

  • Loading branch information
nyalldawson committed Jan 17, 2020
1 parent b14997d commit cbba10b3823fff5b9e325b56a3b993280f539c65
Showing with 39 additions and 2 deletions.
  1. +7 −2 src/core/qgsproject.cpp
  2. +32 −0 tests/src/core/testqgsproject.cpp
@@ -1994,6 +1994,13 @@ bool QgsProject::writeProjectFile( const QString &filename )
QString newSaveUserFull = QgsApplication::userFullName();
qgisNode.setAttribute( QStringLiteral( "saveUser" ), newSaveUser );
qgisNode.setAttribute( QStringLiteral( "saveUserFull" ), newSaveUserFull );
mSaveUser = newSaveUser;
mSaveUserFull = newSaveUserFull;
}
else
{
mSaveUser.clear();
mSaveUserFull.clear();
}
doc->appendChild( qgisNode );

@@ -2234,8 +2241,6 @@ bool QgsProject::writeProjectFile( const QString &filename )
setDirty( false ); // reset to pristine state

emit projectSaved();
mSaveUser = newSaveUser;
mSaveUserFull = newSaveUserFull;
return true;
}

@@ -47,6 +47,7 @@ class TestQgsProject : public QObject
void testReadFlags();
void testSetGetCrs();
void testEmbeddedLayerGroupFromQgz();
void projectSaveUser();
};

void TestQgsProject::init()
@@ -69,6 +70,7 @@ void TestQgsProject::initTestCase()

QgsApplication::init();
QgsApplication::initQgis();
QgsSettings().clear();
}


@@ -485,6 +487,36 @@ void TestQgsProject::testEmbeddedLayerGroupFromQgz()
QCOMPARE( p1.layerIsEmbedded( polys->id() ), path );
}

void TestQgsProject::projectSaveUser()
{
QgsProject p;
QVERIFY( p.saveUser().isEmpty() );
QVERIFY( p.saveUserFullname().isEmpty() );

QTemporaryFile f;
QVERIFY( f.open() );
f.close();
p.setFileName( f.fileName() );
p.write();

QCOMPARE( p.saveUser(), QgsApplication::userLoginName() );
QCOMPARE( p.saveUserFullname(), QgsApplication::userFullName() );

QgsSettings s;
s.setValue( QStringLiteral( "projects/anonymize_saved_projects" ), true, QgsSettings::Core );

p.write();

QVERIFY( p.saveUser().isEmpty() );
QVERIFY( p.saveUserFullname().isEmpty() );

s.setValue( QStringLiteral( "projects/anonymize_saved_projects" ), false, QgsSettings::Core );

p.write();
QCOMPARE( p.saveUser(), QgsApplication::userLoginName() );
QCOMPARE( p.saveUserFullname(), QgsApplication::userFullName() );
}

void TestQgsProject::testSetGetCrs()
{
QgsProject p;

0 comments on commit cbba10b

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