File indexing completed on 2024-11-10 04:40:09

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  *
0006  */
0007 
0008 #include "collectioncreatejob.h"
0009 #include "collectiondeletejob.h"
0010 #include "collectionfetchjob.h"
0011 #include "collectionmodifyjob.h"
0012 #include "entitydisplayattribute.h"
0013 #include "qtest_akonadi.h"
0014 
0015 using namespace Akonadi;
0016 
0017 class CollectionModifyTest : public QObject
0018 {
0019     Q_OBJECT
0020 
0021 private Q_SLOTS:
0022     void initTestCase()
0023     {
0024         AkonadiTest::checkTestIsIsolated();
0025     }
0026 
0027     void testModifyCollection()
0028     {
0029         Collection col;
0030         col.setName(QLatin1StringView("test_collection"));
0031         col.setContentMimeTypes({Collection::mimeType()});
0032         col.setParentCollection(Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res1"))));
0033         col.setRights(Collection::AllRights);
0034 
0035         auto cj = new CollectionCreateJob(col, this);
0036         AKVERIFYEXEC(cj);
0037         col = cj->collection();
0038         QVERIFY(col.isValid());
0039 
0040         auto attr = col.attribute<EntityDisplayAttribute>(Collection::AddIfMissing);
0041         attr->setDisplayName(QStringLiteral("Test Collection"));
0042         col.setContentMimeTypes({Collection::mimeType(), QStringLiteral("application/octet-stream")});
0043 
0044         auto mj = new CollectionModifyJob(col, this);
0045         AKVERIFYEXEC(mj);
0046 
0047         auto fj = new CollectionFetchJob(col, CollectionFetchJob::Base);
0048         AKVERIFYEXEC(fj);
0049         QCOMPARE(fj->collections().count(), 1);
0050         const Collection actual = fj->collections().at(0);
0051 
0052         QCOMPARE(actual.id(), col.id());
0053         QCOMPARE(actual.name(), col.name());
0054         QCOMPARE(actual.displayName(), col.displayName());
0055         QCOMPARE(actual.contentMimeTypes(), col.contentMimeTypes());
0056         QCOMPARE(actual.parentCollection(), col.parentCollection());
0057         QCOMPARE(actual.rights(), col.rights());
0058 
0059         auto dj = new CollectionDeleteJob(col, this);
0060         AKVERIFYEXEC(dj);
0061     }
0062 };
0063 
0064 QTEST_AKONADIMAIN(CollectionModifyTest)
0065 
0066 #include "collectionmodifytest.moc"