diff --git a/tests/testlib/akonadifakedata.cpp b/tests/testlib/akonadifakedata.cpp --- a/tests/testlib/akonadifakedata.cpp +++ b/tests/testlib/akonadifakedata.cpp @@ -108,6 +108,8 @@ const auto oldCollection = m_collections.take(collection.id()); auto newCollection = collection; newCollection.setRemoteId(oldCollection.remoteId()); + if (!newCollection.parentCollection().isValid()) + newCollection.setParentCollection(oldCollection.parentCollection()); if (newCollection.name().isEmpty()) newCollection.setName(oldCollection.name()); if (newCollection.contentMimeTypes().isEmpty()) diff --git a/tests/units/testlib/akonadifakedatatest.cpp b/tests/units/testlib/akonadifakedatatest.cpp --- a/tests/units/testlib/akonadifakedatatest.cpp +++ b/tests/units/testlib/akonadifakedatatest.cpp @@ -150,6 +150,32 @@ QCOMPARE(spy.takeFirst().takeFirst().value(), c2); } + void shouldNotLooseParentCollectionOnModifyCollection() + { + // GIVEN + auto data = Testlib::AkonadiFakeData(); + + auto root = Akonadi::Collection(42); + root.setName("root"); + data.createCollection(root); + + auto c1 = Akonadi::Collection(43); + c1.setName("43"); + c1.setParentCollection(Akonadi::Collection(root.id())); + data.createCollection(c1); + + auto c2 = Akonadi::Collection(c1.id()); + c2.setName("43-bis"); + + // WHEN + data.modifyCollection(c2); + + // THEN + QCOMPARE(data.collections().size(), 2); + QCOMPARE(data.collection(c1.id()), c2); + QCOMPARE(data.collection(c1.id()).parentCollection().id(), root.id()); + } + void shouldListChildCollections() { // GIVEN